[libcxx-commits] [libcxx] [libc++][pair] P2944R3: Constrain `std::pair`'s equality operator (PR #136672)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Wed Apr 23 02:48:46 PDT 2025


================
@@ -447,7 +448,14 @@ pair(_T1, _T2) -> pair<_T1, _T2>;
 
 template <class _T1, class _T2, class _U1, class _U2>
 inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
-operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y) {
+operator==(const pair<_T1, _T2>& __x, const pair<_U1, _U2>& __y)
+#if _LIBCPP_STD_VER >= 26
+  requires requires {
+    { __x.first == __y.first } -> __boolean_testable;
+    { __x.second == __y.second } -> __boolean_testable;
+  }
----------------
frederick-vs-ja wrote:

The standard requirements are inconsistent among these new constraints. _`boolean-testable`_ is used for `pair` and `tuple`'s `operator==`s (perhaps due to _`boolean-testable`_ in old _Preconditions_ added by [P2167R3](https://wg21.link/p2167r3)), while plain implicit convertibility is used elsewhere.

I _guess_ the difference was because of that `&&` (and possibly `||`?) is expected to be used in `pair` and `tuple`'s `operator==`s, but not in other mentioned operators.

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


More information about the libcxx-commits mailing list