diff --git a/libcxx/include/set b/libcxx/include/set --- a/libcxx/include/set +++ b/libcxx/include/set @@ -210,27 +210,31 @@ template bool operator< (const set& x, - const set& y); + const set& y); // removed in C++20 template bool operator!=(const set& x, - const set& y); + const set& y); // removed in C++20 template bool operator> (const set& x, - const set& y); + const set& y); // removed in C++20 template bool operator>=(const set& x, - const set& y); + const set& y); // removed in C++20 template bool operator<=(const set& x, - const set& y); + const set& y); // removed in C++20 + +template + synth-three-way-result operator<=>(const set& x, + const set& y); // since C++20 // specialized algorithms: template @@ -435,27 +439,31 @@ template bool operator< (const multiset& x, - const multiset& y); + const multiset& y); // removed in C++20 template bool operator!=(const multiset& x, - const multiset& y); + const multiset& y); // removed in C++20 template bool operator> (const multiset& x, - const multiset& y); + const multiset& y); // removed in C++20 template bool operator>=(const multiset& x, - const multiset& y); + const multiset& y); // removed in C++20 template bool operator<=(const multiset& x, - const multiset& y); + const multiset& y); // removed in C++20 + +template + synth-three-way-result operator<=>(const multiset& x, + const multiset& y); // since C++20 // specialized algorithms: template @@ -473,6 +481,7 @@ #include <__algorithm/equal.h> #include <__algorithm/lexicographical_compare.h> +#include <__algorithm/lexicographical_compare_three_way.h> #include <__assert> // all public C++ headers provide the assertion handler #include <__config> #include <__functional/is_transparent.h> @@ -982,6 +991,8 @@ return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); } +#if _LIBCPP_STD_VER <= 17 + template inline _LIBCPP_INLINE_VISIBILITY bool @@ -1027,6 +1038,17 @@ return !(__y < __x); } +#else // _LIBCPP_STD_VER <= 17 + +template +inline _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key> +operator<=>(const set<_Key, _Allocator>& __x, const set<_Key, _Allocator>& __y) { + return std::lexicographical_compare_three_way( + __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Key, _Key>); +} + +#endif // _LIBCPP_STD_VER <= 17 + // specialized algorithms: template inline _LIBCPP_INLINE_VISIBILITY @@ -1518,6 +1540,8 @@ return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); } +#if _LIBCPP_STD_VER <= 17 + template inline _LIBCPP_INLINE_VISIBILITY bool @@ -1563,6 +1587,17 @@ return !(__y < __x); } +#else // _LIBCPP_STD_VER <= 17 + +template +inline _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Key> +operator<=>(const multiset<_Key, _Allocator>& __x, const multiset<_Key, _Allocator>& __y) { + return std::lexicographical_compare_three_way( + __x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way<_Key, _Key>); +} + +#endif // _LIBCPP_STD_VER <= 17 + template inline _LIBCPP_INLINE_VISIBILITY void diff --git a/libcxx/test/std/containers/associative/multiset/multiset.nonmember/compare.three_way.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.nonmember/compare.three_way.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.nonmember/compare.three_way.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class multiset + +// template +// synth-three-way-result operator<=>(const multiset& x, +// const multiset& y); + +#include +#include + +#include "test_container_comparisons.h" + +int main(int, char**) { + assert(test_ordered_set_container_spaceship()); + // `std::multiset` is not constexpr, so no `static_assert` test here. + return 0; +} diff --git a/libcxx/test/std/containers/associative/set/set.nonmember/compare.three_way.pass.cpp b/libcxx/test/std/containers/associative/set/set.nonmember/compare.three_way.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.nonmember/compare.three_way.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// UNSUPPORTED: c++03, c++11, c++14, c++17 + +// + +// class set + +// template +// synth-three-way-result operator<=>(const set& x, +// const set& y); + +#include +#include + +#include "test_container_comparisons.h" + +int main(int, char**) { + assert((test_ordered_set_container_spaceship())); + // `std::set` is not constexpr, so no `static_assert` test here. + return 0; +} diff --git a/libcxx/test/support/test_container_comparisons.h b/libcxx/test/support/test_container_comparisons.h --- a/libcxx/test/support/test_container_comparisons.h +++ b/libcxx/test/support/test_container_comparisons.h @@ -10,6 +10,8 @@ #ifndef TEST_CONTAINER_COMPARISONS #define TEST_CONTAINER_COMPARISONS +#include + #include "test_comparisons.h" // Implementation detail of `test_sequence_container_spaceship` @@ -183,7 +185,7 @@ } } -// Tests the `operator<=>` on ordered containers +// Tests the `operator<=>` on ordered map containers template