[libcxx-commits] [libcxx] [libc++] P2944R3: Constrained comparisions - `optional` and `reference_wrapper` (PR #139368)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Mon May 12 00:50:17 PDT 2025


================
@@ -983,72 +984,133 @@ public:
 template <class _Tp>
 optional(_Tp) -> optional<_Tp>;
 
-// Comparisons between optionals
+// [optional.relops] Relational operators
+
+#    if _LIBCPP_STD_VER >= 26
+template < class _Tp, class _Up>
+#    else
 template <
     class _Tp,
     class _Up,
     enable_if_t<is_convertible_v<decltype(std::declval<const _Tp&>() == std::declval<const _Up&>()), bool>, int> = 0>
----------------
frederick-vs-ja wrote:

This is curious. We've been constraining these comparison operators since initially implementing `optional` (a9e659619f592c49b352af16253ec0b79c207956, https://reviews.llvm.org/D22741), although they were not constrained in the standard until C++26.

I guess we should either impose equivalent SFINAE constraints in all modes or remove the constraints before C++26.

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


More information about the libcxx-commits mailing list