| 1 | // { dg-do compile { target c++23 } } |
| 2 | |
| 3 | #include <expected> |
| 4 | #include <testsuite_hooks.h> |
| 5 | |
| 6 | template<typename T, typename U> |
| 7 | concept Eq = requires(T t, U u) { t == u; }; |
| 8 | |
| 9 | static_assert(Eq<std::expected<int, long>, std::expected<short, unsigned>>); |
| 10 | static_assert(Eq<std::expected<void, long>, std::expected<void, unsigned>>); |
| 11 | // static_assert(!Eq<std::expected<void, long>, std::expected<short, unsigned>>); |
| 12 | static_assert(Eq<std::expected<int, long>, short>); |
| 13 | static_assert(!Eq<std::expected<void, long>, short>); |
| 14 | static_assert(Eq<std::expected<int, long>, std::unexpected<short>>); |
| 15 | static_assert(Eq<std::expected<void, long>, std::unexpected<short>>); |
| 16 | |
| 17 | struct NotEqCmp |
| 18 | { |
| 19 | constexpr bool operator==(int) const { return true; } |
| 20 | bool operator==(NotEqCmp) const = delete; |
| 21 | }; |
| 22 | |
| 23 | constexpr bool |
| 24 | test_eq() |
| 25 | { |
| 26 | std::expected<NotEqCmp, int> e1; |
| 27 | VERIFY(e1 == 1); |
| 28 | std::expected<int, int> e2; |
| 29 | VERIFY(e2 == e2); |
| 30 | VERIFY(e1 == e2); |
| 31 | VERIFY(e1 != std::unexpected<int>(1)); |
| 32 | e1 = std::unexpected<int>(1); |
| 33 | VERIFY(e1 == std::unexpected<int>(1)); |
| 34 | VERIFY(e1 != std::unexpected<int>(2)); |
| 35 | VERIFY(e1 != e2); |
| 36 | |
| 37 | std::expected<void, int> e3; |
| 38 | VERIFY(e3 == e3); |
| 39 | VERIFY(e3 != std::unexpected<int>(1)); |
| 40 | e3 = std::unexpected<int>(1); |
| 41 | VERIFY(e3 == e3); |
| 42 | VERIFY(e3 == std::unexpected<int>(1)); |
| 43 | VERIFY(e3 != std::unexpected<int>(2)); |
| 44 | |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | static_assert( test_eq() ); |