{ return !__rhs || __lhs >= *__rhs; }
#ifdef __cpp_lib_three_way_comparison
+ template<typename _Tp>
+ inline constexpr bool __is_optional_v = false;
+ template<typename _Tp>
+ inline constexpr bool __is_optional_v<optional<_Tp>> = true;
+
template<typename _Tp, typename _Up>
+ requires (!__is_optional_v<_Up>)
+ && three_way_comparable_with<_Tp, _Up>
constexpr compare_three_way_result_t<_Tp, _Up>
operator<=>(const optional<_Tp>& __x, const _Up& __v)
{ return bool(__x) ? *__x <=> __v : strong_ordering::less; }
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-// { dg-options "-std=gnu++2a" }
-// { dg-do compile { target c++2a } }
+// { dg-options "-std=gnu++20" }
+// { dg-do compile { target c++20 } }
#include <optional>
static_assert( nullopt <= O{} );
static_assert( nullopt <= O{1} );
}
+
+template<typename T>
+ concept has_spaceship = requires (const T& t) { t <=> t; };
+
+void
+test03()
+{
+ struct E
+ {
+ auto operator<=>(const E&) const { return std::strong_ordering::equal; }
+ };
+ static_assert( !std::three_way_comparable<E> ); // not equality comparable
+ using O = std::optional<E>;
+ static_assert( !std::three_way_comparable<O> );
+ static_assert( ! has_spaceship<O> ); // PR libstdc++/98842
+ struct U : O { };
+ static_assert( ! has_spaceship<U> );
+}