[libc++] P2944R3: Constrained comparisions - tuple (#145677)
Implements P2944R3 partially, which adds constrained comparisons
`std::tuple`.
The missing overloads introduced in [P2165R4](https://wg21.link/P2165R4)
are not implemented.
Uses
[`__all`](f7af33a9eb/libcxx/include/__type_traits/conjunction.h (L45))
instead of a fold expression, see comment:
https://github.com/llvm/llvm-project/pull/141396#discussion_r2161166077
Relates to #136765
# References
[tuple.rel](https://wg21.link//tuple.rel)
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|","","The changes to ``optional`` and ``tuple`` are not yet implemented"
|
||||
"`P2944R3 <https://wg21.link/P2944R3>`__","Comparisons for ``reference_wrapper``","2024-03 (Tokyo)","|Partial|","","The changes to ``optional`` and ``tuple``'s equality overload from P2165R4 are not yet implemented"
|
||||
"`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",""
|
||||
"","","","","",""
|
||||
|
||||
|
@@ -216,6 +216,7 @@ template <class... Types>
|
||||
# include <__compare/common_comparison_category.h>
|
||||
# include <__compare/ordering.h>
|
||||
# include <__compare/synth_three_way.h>
|
||||
# include <__concepts/boolean_testable.h>
|
||||
# include <__config>
|
||||
# include <__cstddef/size_t.h>
|
||||
# include <__fwd/array.h>
|
||||
@@ -1153,6 +1154,11 @@ struct __tuple_equal<0> {
|
||||
};
|
||||
|
||||
template <class... _Tp, class... _Up>
|
||||
# if _LIBCPP_STD_VER >= 26
|
||||
requires(__all<requires(const _Tp& __t, const _Up& __u) {
|
||||
{ __t == __u } -> __boolean_testable;
|
||||
}...>::value && (sizeof...(_Tp) == sizeof...(_Up)))
|
||||
# endif
|
||||
inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
|
||||
operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y) {
|
||||
static_assert(sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
|
||||
|
||||
@@ -16,12 +16,33 @@
|
||||
|
||||
// UNSUPPORTED: c++03
|
||||
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <tuple>
|
||||
|
||||
#include "test_comparisons.h"
|
||||
#include "test_macros.h"
|
||||
|
||||
#if TEST_STD_VER >= 26
|
||||
|
||||
// Test SFINAE.
|
||||
|
||||
static_assert(std::equality_comparable<std::tuple<EqualityComparable>>);
|
||||
static_assert(std::equality_comparable<std::tuple<EqualityComparable, EqualityComparable>>);
|
||||
|
||||
static_assert(!std::equality_comparable<std::tuple<NonComparable>>);
|
||||
static_assert(!std::equality_comparable<std::tuple<EqualityComparable, NonComparable>>);
|
||||
static_assert(!std::equality_comparable<std::tuple<NonComparable, EqualityComparable>>);
|
||||
static_assert(!std::equality_comparable_with<std::tuple<EqualityComparable>, std::tuple<NonComparable>>);
|
||||
static_assert(!std::equality_comparable_with<std::tuple<NonComparable>, std::tuple<EqualityComparable>>);
|
||||
// Size mismatch.
|
||||
static_assert(
|
||||
!std::equality_comparable_with<std::tuple<EqualityComparable>, std::tuple<EqualityComparable, EqualityComparable>>);
|
||||
static_assert(
|
||||
!std::equality_comparable_with<std::tuple<EqualityComparable, EqualityComparable>, std::tuple<EqualityComparable>>);
|
||||
|
||||
#endif
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
{
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// Disabled in C++26 and later because tuple comparison between different sizes is constrained since P2944R3.
|
||||
// UNSUPPORTED: std-at-least-cxx26
|
||||
|
||||
// <tuple>
|
||||
|
||||
// template <class... Types> class tuple;
|
||||
|
||||
Reference in New Issue
Block a user