[libcxx-commits] [libcxx] Make std::nullopt_t comparable (PR #195549)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 4 03:22:24 PDT 2026


================
@@ -362,6 +362,9 @@ struct nullopt_t {
     explicit __secret_tag() = default;
   };
   _LIBCPP_HIDE_FROM_ABI constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {}
+#    if _LIBCPP_STD_VER >= 26
+  _LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const nullopt_t&) const noexcept = default;
+#    endif
----------------
frederick-vs-ja wrote:

I think we should implement LWG4497 in C++17 and later.

For C++20 and later, we can just use `operator<=>`. In C++17 mode, there should be 6 manually written operators.

Also, IMO hidden friends are better.

https://github.com/llvm/llvm-project/pull/195549


More information about the libcxx-commits mailing list