[libc++][pair] P2944R3: Constrain std::pair's equality operator (#136672)
Implements https://wg21.link/P2944R3 (partially): - [pairs.spec](https://eel.is/c++draft/pairs.spec) Related issues: - Related to #105424 - Related to #118135 - PR https://github.com/llvm/llvm-project/pull/135759 - PR https://github.com/llvm/llvm-project/pull/117664 Closes: [#136763](https://github.com/llvm/llvm-project/issues/136763) # References - https://eel.is/c++draft/concept.booleantestable - https://eel.is/c++draft/concept.equalitycomparable --------- Co-authored-by: Hristo Hristov <zingam@outlook.com> Co-authored-by: Nikolas Klauser <nikolasklauser@berlin.de>
This commit is contained in:
@@ -59,7 +59,7 @@
|
||||
"`P2248R8 <https://wg21.link/P2248R8>`__","Enabling list-initialization for algorithms","2024-03 (Tokyo)","","",""
|
||||
"`P2810R4 <https://wg21.link/P2810R4>`__","``is_debugger_present`` ``is_replaceable``","2024-03 (Tokyo)","","",""
|
||||
"`P1068R11 <https://wg21.link/P1068R11>`__","Vector API for random number generation","2024-03 (Tokyo)","","",""
|
||||
"`P2944R3 <https://wg21.link/P2944R3>`__","Comparisons for ``reference_wrapper``","2024-03 (Tokyo)","|Partial|","19","Implemented comparisons for ``reference_wrapper`` only"
|
||||
"`P2944R3 <https://wg21.link/P2944R3>`__","Comparisons for ``reference_wrapper``","2024-03 (Tokyo)","|Partial|","","Implemented changes to ``reference_wrapper`` and ``pair``"
|
||||
"`P2642R6 <https://wg21.link/P2642R6>`__","Padded ``mdspan`` layouts","2024-03 (Tokyo)","","",""
|
||||
"`P3029R1 <https://wg21.link/P3029R1>`__","Better ``mdspan``'s CTAD","2024-03 (Tokyo)","|Complete|","19",""
|
||||
"","","","","",""
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <__compare/common_comparison_category.h>
|
||||
#include <__compare/synth_three_way.h>
|
||||
#include <__concepts/boolean_testable.h>
|
||||
#include <__concepts/different_from.h>
|
||||
#include <__config>
|
||||
#include <__cstddef/size_t.h>
|
||||
@@ -461,7 +462,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;
|
||||
}
|
||||
#endif
|
||||
{
|
||||
return __x.first == __y.first && __x.second == __y.second;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,35 @@
|
||||
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
#include <concepts>
|
||||
|
||||
#include "test_macros.h"
|
||||
|
||||
#if TEST_STD_VER >= 26
|
||||
|
||||
// Test SFINAE.
|
||||
|
||||
struct EqualityComparable {
|
||||
constexpr EqualityComparable(int value) : value_{value} {};
|
||||
|
||||
friend constexpr bool operator==(const EqualityComparable&, const EqualityComparable&) noexcept = default;
|
||||
|
||||
int value_;
|
||||
};
|
||||
|
||||
static_assert(std::equality_comparable<EqualityComparable>);
|
||||
|
||||
static_assert(std::equality_comparable<std::pair<EqualityComparable, EqualityComparable>>);
|
||||
|
||||
struct NonComparable {};
|
||||
|
||||
static_assert(!std::equality_comparable<NonComparable>);
|
||||
|
||||
static_assert(!std::equality_comparable<std::pair<EqualityComparable, NonComparable>>);
|
||||
static_assert(!std::equality_comparable<std::pair<NonComparable, EqualityComparable>>);
|
||||
|
||||
#endif // TEST_STD_VER >= 26
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user