// { 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::optional& t, const std::optional& u) { t == u; *t == u; t == *u; }; template concept ne_comparable = requires (const std::optional& t, const std::optional& u) { t != u; *t != u; t != *u; }; template concept lt_comparable = requires (const std::optional& t, const std::optional& u) { t < u; *t < u; t < *u; }; template concept le_comparable = requires (const std::optional& t, const std::optional& u) { t <= u; *t <= u; t <= *u; }; template concept gt_comparable = requires (const std::optional& t, const std::optional& u) { t > u; *t > u; t > *u; }; template concept ge_comparable = requires (const std::optional& t, const std::optional& u) { t >= u; *t >= u; t >= *u; }; 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 ); 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 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 ); 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 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( eq_comparable ); static_assert( ne_comparable ); static_assert( eq_comparable ); static_assert( ne_comparable ); struct D { }; int operator==(D, D); bool operator!=(D, D) = delete; 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( eq_comparable ); static_assert( ! ne_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 ); static_assert( ! eq_comparable ); static_assert( ! eq_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 ); static_assert( lt_comparable ); static_assert( lt_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 ); static_assert( le_comparable ); static_assert( le_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); // non-bool prevents synthesis of != void operator<=(K, K); std::weak_ordering operator<=>(K, K); static_assert( eq_comparable ); static_assert( ! ne_comparable ); static_assert( lt_comparable ); static_assert( ! le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); bool operator==(A, B); static_assert( eq_comparable ); static_assert( eq_comparable ); static_assert( ne_comparable ); static_assert( ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); int operator==(C, D); // non-bool prevents synthesis of != and reversed args static_assert( eq_comparable ); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! ne_comparable ); static_assert( ! lt_comparable ); static_assert( ! le_comparable ); static_assert( ! gt_comparable ); static_assert( ! ge_comparable ); std::weak_ordering operator<=>(E, F); static_assert( ! eq_comparable ); static_assert( ! eq_comparable ); static_assert( ! ne_comparable ); static_assert( ! ne_comparable ); static_assert( lt_comparable ); static_assert( le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable ); static_assert( lt_comparable ); static_assert( le_comparable ); static_assert( gt_comparable ); static_assert( ge_comparable );