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

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jun 23 22:59:47 PDT 2025


================
@@ -982,72 +983,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>
-_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const optional<_Up>& __y) {
+#    endif
+_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const optional<_Tp>& __x, const optional<_Up>& __y)
+#    if _LIBCPP_STD_VER >= 26
+  requires requires {
+    { *__x == *__y } -> __core_convertible_to<bool>;
----------------
frederick-vs-ja wrote:

Looks like that the controversy about constraints before C++26 won't be resolved soon, and other implementations also constrain these operators since C++17. Perhaps at this moment we can use `__is_core_convertible` and traditional SFINAE in all modes. @H-G-Hristov @Zingam 

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


More information about the libcxx-commits mailing list