[libcxx-commits] [libcxx] [libc++] LWG4497: `std::nullopt_t` should be comparable (PR #195549)
A. Jiang via libcxx-commits
libcxx-commits at lists.llvm.org
Thu May 14 01:18:58 PDT 2026
================
@@ -362,6 +362,16 @@ struct nullopt_t {
explicit __secret_tag() = default;
};
_LIBCPP_HIDE_FROM_ABI constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {}
+# if _LIBCPP_STD_VER <= 17
+ _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator==(nullopt_t, nullopt_t) { return true; }
+ _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator!=(nullopt_t, nullopt_t) { return false; }
+ _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator>(nullopt_t, nullopt_t) { return false; }
+ _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator<(nullopt_t, nullopt_t) { return false; }
+ _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator>=(nullopt_t, nullopt_t) { return true; }
+ _LIBCPP_HIDE_FROM_ABI constexpr friend bool operator<=(nullopt_t, nullopt_t) { return true; }
+# else
+ _LIBCPP_HIDE_FROM_ABI constexpr friend strong_ordering operator<=>(nullopt_t, nullopt_t) = default;
+# endif
----------------
frederick-vs-ja wrote:
Actually, we don't need explicitly write `constexpr` or `noexcept` for the defaulted `operator<=>`, as compilers are required to deduce these.
https://github.com/llvm/llvm-project/pull/195549
More information about the libcxx-commits
mailing list