diff --git a/libcxx/docs/Status/Cxx2cPapers.csv b/libcxx/docs/Status/Cxx2cPapers.csv index 3809446a57896..8a0417e120d75 100644 --- a/libcxx/docs/Status/Cxx2cPapers.csv +++ b/libcxx/docs/Status/Cxx2cPapers.csv @@ -59,7 +59,7 @@ "`P2248R8 `__","Enabling list-initialization for algorithms","2024-03 (Tokyo)","","","" "`P2810R4 `__","``is_debugger_present`` ``is_replaceable``","2024-03 (Tokyo)","","","" "`P1068R11 `__","Vector API for random number generation","2024-03 (Tokyo)","","","" -"`P2944R3 `__","Comparisons for ``reference_wrapper``","2024-03 (Tokyo)","|Partial|","","Implemented changes to ``reference_wrapper`` and ``pair``" +"`P2944R3 `__","Comparisons for ``reference_wrapper``","2024-03 (Tokyo)","|Partial|","","The changes to ``optional``, ``tuple`` and ``variant`` are not yet implemented" "`P2642R6 `__","Padded ``mdspan`` layouts","2024-03 (Tokyo)","","","" "`P3029R1 `__","Better ``mdspan``'s CTAD","2024-03 (Tokyo)","|Complete|","19","" "","","","","","" diff --git a/libcxx/include/__functional/reference_wrapper.h b/libcxx/include/__functional/reference_wrapper.h index b409ad7511f6c..c46203a4ca9a4 100644 --- a/libcxx/include/__functional/reference_wrapper.h +++ b/libcxx/include/__functional/reference_wrapper.h @@ -11,7 +11,6 @@ #define _LIBCPP___FUNCTIONAL_REFERENCE_WRAPPER_H #include <__compare/synth_three_way.h> -#include <__concepts/boolean_testable.h> #include <__config> #include <__functional/weak_result_type.h> #include <__memory/addressof.h> @@ -19,6 +18,7 @@ #include <__type_traits/enable_if.h> #include <__type_traits/invoke.h> #include <__type_traits/is_const.h> +#include <__type_traits/is_core_convertible.h> #include <__type_traits/remove_cvref.h> #include <__type_traits/void_t.h> #include <__utility/declval.h> @@ -75,7 +75,7 @@ class reference_wrapper : public __weak_result_type<_Tp> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y) requires requires { - { __x.get() == __y.get() } -> __boolean_testable; + { __x.get() == __y.get() } -> __core_convertible_to; } { return __x.get() == __y.get(); @@ -83,7 +83,7 @@ class reference_wrapper : public __weak_result_type<_Tp> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, const _Tp& __y) requires requires { - { __x.get() == __y } -> __boolean_testable; + { __x.get() == __y } -> __core_convertible_to; } { return __x.get() == __y; @@ -91,7 +91,7 @@ class reference_wrapper : public __weak_result_type<_Tp> { _LIBCPP_HIDE_FROM_ABI friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y) requires(!is_const_v<_Tp>) && requires { - { __x.get() == __y.get() } -> __boolean_testable; + { __x.get() == __y.get() } -> __core_convertible_to; } { return __x.get() == __y.get(); diff --git a/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp b/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp index 01be1db73041b..671747f89a82e 100644 --- a/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp +++ b/libcxx/test/std/containers/sequences/array/compare.three_way.pass.cpp @@ -26,7 +26,6 @@ constexpr std::size_t N{1}; static_assert(std::three_way_comparable>); // Thanks to SFINAE, the following is not a compiler error but returns `false` -struct NonComparable {}; static_assert(!std::three_way_comparable>); // Implementation detail of `test_sequence_container_array_spaceship` diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp index 85106c18ec35a..4a2ae963e3bdb 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.const_ref.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,16 +23,13 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(HasSpaceshipOperatorWithInt>); -static_assert(HasSpaceshipOperatorWithInt>); -static_assert(HasSpaceshipOperatorWithInt>); +static_assert(HasOperatorSpaceship, int>); +static_assert(HasOperatorSpaceship, int>); +static_assert(HasOperatorSpaceship, int>); -static_assert(!HasSpaceshipOperatorWithInt>); +static_assert(!HasOperatorSpaceship, int>); // Test comparisons. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp index 794fac00de8a6..3d72459bc5a19 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -22,17 +22,13 @@ #include "test_comparisons.h" #include "test_macros.h" - -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::three_way_comparable>); -static_assert(std::three_way_comparable>); -static_assert(std::three_way_comparable>); +static_assert(HasOperatorSpaceship>); +static_assert(HasOperatorSpaceship>); +static_assert(HasOperatorSpaceship>); -static_assert(!std::three_way_comparable>); +static_assert(!HasOperatorSpaceship>); // Test comparisons. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp index 9b1302affa851..1ae22b4ac58e0 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/compare.three_way.refwrap.refwrap_const.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,18 +23,15 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::three_way_comparable_with, const StrongOrder>); -static_assert(std::three_way_comparable_with, const WeakOrder>); -static_assert(std::three_way_comparable_with, const PartialOrder>); +static_assert(HasOperatorSpaceship, std::reference_wrapper>); +static_assert(HasOperatorSpaceship, std::reference_wrapper>); +static_assert(HasOperatorSpaceship, std::reference_wrapper>); -static_assert(!std::three_way_comparable_with, const NonComparable>); -static_assert(!std::three_way_comparable_with, const NonComparable>); -static_assert(!std::three_way_comparable_with, const NonComparable>); +static_assert(!HasOperatorSpaceship, std::reference_wrapper>); +static_assert(!HasOperatorSpaceship, std::reference_wrapper>); +static_assert(!HasOperatorSpaceship, std::reference_wrapper>); // Test comparisons. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp index 465326818f17c..316ff7c303315 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.const_ref.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,14 +23,13 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(HasEqualityOperatorWithInt>); +static_assert(HasOperatorEqual>); +static_assert(HasOperatorEqual, int>); -static_assert(!HasEqualityOperatorWithInt>); +static_assert(!HasOperatorEqual>); +static_assert(!HasOperatorEqual, int>); // Test equality. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp index a50b530bbc6e1..70e79d399861a 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -22,14 +22,11 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::equality_comparable>); +static_assert(HasOperatorEqual>); -static_assert(!std::equality_comparable>); +static_assert(!HasOperatorEqual>); // Test equality. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp index 10f017742a87f..c68ad5c4aa527 100644 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp +++ b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.refwrap.refwrap_const.pass.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20, c++23 +// REQUIRES: std-at-least-c++26 // @@ -23,16 +23,13 @@ #include "test_comparisons.h" #include "test_macros.h" -#include "helper_concepts.h" -#include "helper_types.h" - // Test SFINAE. -static_assert(std::equality_comparable_with, - std::reference_wrapper>); +static_assert( + HasOperatorEqual, std::reference_wrapper>); -static_assert(!std::equality_comparable_with, - std::reference_wrapper>); +static_assert( + !HasOperatorEqual, std::reference_wrapper>); // Test equality. diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_concepts.h b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_concepts.h deleted file mode 100644 index 2dbb304f8af63..0000000000000 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_concepts.h +++ /dev/null @@ -1,38 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_CONCEPTS_H -#define TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_CONCEPTS_H - -#include -#include - -// Equality - -template -concept HasEqualityOperatorWithInt = requires(T t, int i) { - { t.get() == i } -> std::convertible_to; -}; - -// Spaceship - -template -concept BooleanTestableImpl = std::convertible_to; - -template -concept BooleanTestable = BooleanTestableImpl && requires(T&& t) { - { !std::forward(t) } -> BooleanTestableImpl; -}; - -template -concept HasSpaceshipOperatorWithInt = requires(T t, int i) { - { t < i } -> BooleanTestable; - { i < t } -> BooleanTestable; -}; - -#endif // TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_CONCEPTS_H diff --git a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_types.h b/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_types.h deleted file mode 100644 index cf5e568dbf936..0000000000000 --- a/libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/helper_types.h +++ /dev/null @@ -1,30 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_TYPES_H -#define TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_TYPES_H - -#include - -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); -static_assert(EqualityComparable{94} == EqualityComparable{94}); -static_assert(EqualityComparable{94} != EqualityComparable{82}); - -struct NonComparable {}; - -static_assert(!std::three_way_comparable); - -#endif // TEST_STD_FUNCTIONOBJECTS_REFWRAP_HELPER_TYPES_H diff --git a/libcxx/test/support/test_comparisons.h b/libcxx/test/support/test_comparisons.h index db6977a96a2fe..d9729e0451b49 100644 --- a/libcxx/test/support/test_comparisons.h +++ b/libcxx/test/support/test_comparisons.h @@ -268,6 +268,29 @@ struct PartialOrder { } }; -#endif +template +concept HasOperatorEqual = requires(T1 t1, T2 t2) { t1 == t2; }; + +template +concept HasOperatorSpaceship = requires(T1 t1, T2 t2) { t1 <=> t2; }; + +struct NonComparable {}; +static_assert(!std::equality_comparable); +static_assert(!HasOperatorEqual); +static_assert(!HasOperatorSpaceship); + +class EqualityComparable { +public: + constexpr EqualityComparable(int value) : value_{value} {}; + + friend constexpr bool operator==(const EqualityComparable&, const EqualityComparable&) noexcept = default; + +private: + int value_; +}; +static_assert(std::equality_comparable); +static_assert(HasOperatorEqual); + +#endif // TEST_STD_VER >= 20 #endif // TEST_COMPARISONS_H diff --git a/libcxx/test/support/test_container_comparisons.h b/libcxx/test/support/test_container_comparisons.h index f7bf78e48a1f8..53db5ba99ce47 100644 --- a/libcxx/test/support/test_container_comparisons.h +++ b/libcxx/test/support/test_container_comparisons.h @@ -88,7 +88,6 @@ constexpr bool test_sequence_container_spaceship() { std::weak_ordering>(); // Thanks to SFINAE, the following is not a compiler error but returns `false` - struct NonComparable {}; static_assert(!std::three_way_comparable>); return true; @@ -163,7 +162,6 @@ constexpr void test_sequence_container_adaptor_spaceship_with_type() { template