[libcxx-commits] [libcxx] [llvm] [libc++] Implement P3379R0 Constrain `std::expected` equality operators (PR #135759)

via libcxx-commits libcxx-commits at lists.llvm.org
Sat Apr 26 08:33:07 PDT 2025


================
@@ -1139,8 +1140,15 @@ class expected : private __expected_base<_Tp, _Err> {
 
   // [expected.object.eq], equality operators
   template <class _T2, class _E2>
+  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y)
     requires(!is_void_v<_T2>)
-  _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(const expected& __x, const expected<_T2, _E2>& __y) {
+#  if _LIBCPP_STD_VER >= 26
+            && requires {
+                 { *__x == *__y } -> __core_convertible_to<bool>;
----------------
yronglin wrote:

Thanks for the review! This because I followed https://github.com/llvm/llvm-project/pull/117664#discussion_r1857826166, but seems the standard wording is the following:
> Constraints: T2 is not a specialization of expected[.](https://eel.is/c++draft/expected#object.eq-3.sentence-1) The expression *x == v is well-formed and its result is convertible to bool[.](https://eel.is/c++draft/expected#object.eq-3.sentence-2)

I'm not sure I missed any LWG issues or other things.

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


More information about the libcxx-commits mailing list