diff --git a/example/matcher.cpp b/example/matcher.cpp index d4461b1e..02ac674a 100644 --- a/example/matcher.cpp +++ b/example/matcher.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include struct expr { const bool result{}; @@ -19,6 +21,29 @@ struct expr { } }; +template +class any_of { + public: + constexpr explicit any_of(Ts... ts) : ts_{ts...} {} + + constexpr auto operator==(std::common_type_t t) const { + return std::apply([t](auto... args) { return eq(t, args...); }, ts_); + } + + private: + template + static constexpr auto eq(const T& t, const U& u, const TArgs&... args) { + using namespace boost::ut; + if constexpr (sizeof...(args) > 0) { + return (that % detail::value{u} == t) or eq(t, args...); + } else { + return (that % detail::value{u} == t); + } + } + + std::tuple ts_; +}; + int main() { using namespace boost::ut; using namespace std::literals::string_view_literals; @@ -45,5 +70,6 @@ int main() { expect(is_between(1, 100)(value) and ends_with(str, ".test"sv)); expect(not is_between(1, 100)(0)); + expect(any_of{1, 2, 3} == 2 or any_of{42, 43} == 44); }; }