// { dg-do compile { target c++20 } } #include #ifndef __cpp_lib_constrained_equality # error "Feature-test macro for constrained_equality missing" #elif __cpp_lib_constrained_equality < 202403L # error "Feature-test macro for constrained_equality has wrong value" #endif template concept eq_comparable = requires (const std::variant& t) { t == t; }; template concept ne_comparable = requires (const std::variant& t) { t != t; }; template concept lt_comparable = requires (const std::variant& t) { t < t; }; template concept le_comparable = requires (const std::variant& t) { t <= t; }; template concept gt_comparable = requires (const std::variant& t) { t > t; }; template concept ge_comparable = requires (const std::variant& t) { t >= t; }; static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( lt_comparable ); static_assert( le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( lt_comparable ); static_assert( le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( lt_comparable ); static_assert( le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( lt_comparable ); static_assert( le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); struct A { }; static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); struct B { }; void operator==(B, B); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); struct C { }; bool operator==(C, C); static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); static_assert( ne_comparable ); struct D { }; int operator==(D, D); // variant's operator== returns bool despite int here bool operator!=(D, D) = delete; static_assert( eq_comparable ); static_assert( ne_comparable ); // variant's operator== can be used static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); struct E { }; bool operator==(/* not-const */ E&, const E&); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); struct F { }; bool operator<(F, F); void operator>(F, F); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); struct G { }; bool operator<=(G, G); void operator<(G, G); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! lt_comparable ); static_assert( le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); struct H { }; bool operator>(H, H); void operator>=(H, H); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( gt_comparable ); static_assert( ! ge_comparable ); static_assert( gt_comparable ); static_assert( gt_comparable ); struct I { }; bool operator>=(I, I); void operator<=(I, I); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ge_comparable ); static_assert( ge_comparable ); static_assert( ge_comparable ); struct J { }; bool operator==(J, J); std::weak_ordering operator<=>(J, J); static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( lt_comparable ); static_assert( le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); struct K { }; int operator==(K, K); // variant's operator== returns bool despite int here void operator<=(K, K); std::weak_ordering operator<=>(K, K); static_assert( eq_comparable ); static_assert( ne_comparable ); // variant's operator== can be used static_assert( lt_comparable ); static_assert( ! le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( lt_comparable ); static_assert( ! le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable );