File tree 3 files changed +54
-0
lines changed
3 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 8
8
#include < match/or.hpp>
9
9
#include < match/simplify.hpp>
10
10
11
+ #include < compare>
12
+ #include < utility>
13
+
11
14
template <match::matcher L, match::matcher R>
12
15
[[nodiscard]] constexpr auto operator and (L const &lhs, R const &rhs)
13
16
-> decltype(match::simplify(std::declval<match::and_t <L, R>>())) {
@@ -25,3 +28,16 @@ template <match::matcher M>
25
28
-> decltype(match::simplify(match::negate(std::declval<M>()))) {
26
29
return match::simplify (match::negate (m));
27
30
}
31
+
32
+ template <match::matcher L, match::matcher R>
33
+ [[nodiscard]] constexpr auto operator <=>(L const &lhs, R const &rhs)
34
+ -> std::partial_ordering {
35
+ auto const l = match::simplify (lhs);
36
+ auto const r = match::simplify (rhs);
37
+ auto const x = match::implies (l, r);
38
+ auto const y = match::implies (r, l);
39
+ if (not x and not y) {
40
+ return std::partial_ordering::unordered;
41
+ }
42
+ return x <=> y;
43
+ }
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ add_tests(
38
38
lookup/strategies
39
39
match/and
40
40
match/constant
41
+ match/equivalence
41
42
match/implies
42
43
match/not
43
44
match/or
Original file line number Diff line number Diff line change
1
+ #include " test_matcher.hpp"
2
+
3
+ #include < match/ops.hpp>
4
+
5
+ #include < catch2/catch_test_macros.hpp>
6
+
7
+ #include < compare>
8
+ #include < type_traits>
9
+
10
+ TEST_CASE (" less than" , " [match equivalence]" ) {
11
+ using T = test_m<0 >;
12
+ using U = match::and_t <T, test_m<1 >>;
13
+ constexpr auto result = T{} <=> U{};
14
+ static_assert (result == std::partial_ordering::less);
15
+ static_assert (T{} < U{});
16
+ }
17
+
18
+ TEST_CASE (" greater than" , " [match equivalence]" ) {
19
+ using T = test_m<0 >;
20
+ using U = match::or_t <T, test_m<1 >>;
21
+ constexpr auto result = T{} <=> U{};
22
+ static_assert (result == std::partial_ordering::greater);
23
+ static_assert (T{} > U{});
24
+ }
25
+
26
+ TEST_CASE (" equivalent" , " [match equivalence]" ) {
27
+ using T = test_m<0 >;
28
+ constexpr auto result = T{} <=> T{};
29
+ static_assert (result == std::partial_ordering::equivalent);
30
+ }
31
+
32
+ TEST_CASE (" unorderable" , " [match equivalence]" ) {
33
+ using T = test_m<0 >;
34
+ using U = test_m<1 >;
35
+ constexpr auto result = T{} <=> U{};
36
+ static_assert (result == std::partial_ordering::unordered);
37
+ }
You can’t perform that action at this time.
0 commit comments