cortexlib  v0.2.0
match.hxx
Go to the documentation of this file.
1 // -*- C++ -*- Header compatibility <match.hxx>
2 
18 
19 #ifndef CORTEX_MATCH
20 #define CORTEX_MATCH
21 
22 #include <utility>
23 #include <variant>
24 
25 #if __cpp_concepts >= 201907L
26 # include <concepts>
27 #endif //< __cpp_concepts >= 201907L
28 
29 namespace cxl::utils
30 {
31 
40  template<typename... Fs>
41  struct match : Fs...
42  {
43 
53  template<class... Ts>
54  explicit match(Ts&&... ts)
55  : Fs { std::forward<Ts>(ts) }... { }
56 
61  using Fs::operator()...;
62 
63  }; //< class match
64 
66  template<typename... Fs>
68 
80  template<typename... Ts, typename... Fs>
81  constexpr auto
83  const std::variant<Ts...>& var,
84  const match<Fs...>& m
85  ) -> void
86  { std::visit(m, var); }
87 
101  template<typename... Ts, typename... Fs>
102  constexpr auto
103  operator<< (
104  const std::variant<Ts...>& var,
105  const match<Fs...>& m
106  ) -> decltype(auto)
107  { return std::visit(m, var); }
108 
116  struct match_any
117  {
118  template<typename T>
119  explicit constexpr match_any([[maybe_unused]] T&& t) noexcept { }
120 
121  explicit constexpr match_any(const match_any&) noexcept = delete;
122  explicit constexpr match_any(match_any&&) noexcept = delete;
123 
124  constexpr auto
125  operator= (const match_any&) noexcept -> match_any& = delete;
126 
127  constexpr auto
128  operator= (match_any&&) noexcept -> match_any& = delete;
129 
130  constexpr ~match_any() noexcept = delete;
131  };
132 
133 } //< namespace cxl::utils
134 
135 #endif //< CORTEX_MATCH
Definition: match.hxx:30
constexpr auto operator>>(const std::variant< Ts... > &var, const match< Fs... > &m) -> void
Match Expression Notation.
Definition: match.hxx:82
match(Fs &&...) -> match< std::remove_reference_t< Fs >... >
Template Deduction Guide.
constexpr auto operator<<(const std::variant< Ts... > &var, const match< Fs... > &m) -> decltype(auto)
Match Expression Assignment Overload.
Definition: match.hxx:103
Definition: matrix.hxx:1310
Wildcard Empty Placeholder.
Definition: match.hxx:117
constexpr match_any(match_any &&) noexcept=delete
constexpr match_any(const match_any &) noexcept=delete
constexpr match_any([[maybe_unused]] T &&t) noexcept
Definition: match.hxx:119
match structure
Definition: match.hxx:42
match(Ts &&... ts)
Forward Constructor.
Definition: match.hxx:54