diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv --- a/libcxx/docs/Status/SpaceshipProjects.csv +++ b/libcxx/docs/Status/SpaceshipProjects.csv @@ -40,8 +40,8 @@ | `[forward.list.syn] `_ (`general `_),| `forward_list `_,[expos.only.func],Hristo Hristov,|Complete| | `[list.syn] `_ (`general `_),| `list `_,[expos.only.func],Adrian Vogelsgesang,|Complete| | `[vector.syn] `_ (`general `_),| `vector `_,[expos.only.func],Adrian Vogelsgesang,|In Progress| -| `[associative.map.syn] `_ (`general `_),"| map -| multimap",[expos.only.func],Unassigned,|Not Started| +| `[associative.map.syn] `_ (`general `_),"| `map `_ +| `multimap `_",[expos.only.func],Hristo Hristov,|Complete| | `[associative.set.syn] `_ (`general `_),"| multiset | set",[expos.only.func],Unassigned,|Not Started| | `[queue.ops] `_,| queue,None,Unassigned,|Not Started| diff --git a/libcxx/include/map b/libcxx/include/map --- a/libcxx/include/map +++ b/libcxx/include/map @@ -250,27 +250,32 @@ template bool operator< (const map& x, - const map& y); + const map& y); // removed in C++20 template bool operator!=(const map& x, - const map& y); + const map& y); // removed in C++20 template bool operator> (const map& x, - const map& y); + const map& y); // removed in C++20 template bool operator>=(const map& x, - const map& y); + const map& y); // removed in C++20 template bool operator<=(const map& x, - const map& y); + const map& y); // removed in C++20 + +template + synth-three-way-result> + operator<=>(const map& x, + const map& y); // since C++20 // specialized algorithms: template @@ -491,27 +496,32 @@ template bool operator< (const multimap& x, - const multimap& y); + const multimap& y); // removed in C++20 template bool operator!=(const multimap& x, - const multimap& y); + const multimap& y); // removed in C++20 template bool operator> (const multimap& x, - const multimap& y); + const multimap& y); // removed in C++20 template bool operator>=(const multimap& x, - const multimap& y); + const multimap& y); // removed in C++20 template bool operator<=(const multimap& x, - const multimap& y); + const multimap& y); // removed in C++20 + +template + synth-three-way-result> + operator<=>(const multimap& x, + const multimap& y); // since c++20 // specialized algorithms: template @@ -530,6 +540,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/binary_function.h> @@ -1676,6 +1687,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 @@ -1721,6 +1734,20 @@ return !(__y < __x); } +#else // #if _LIBCPP_STD_VER <= 17 + +template +inline _LIBCPP_HIDE_FROM_ABI +__synth_three_way_result> +operator<=>(const map<_Key, _Tp, _Compare, _Allocator>& __x, + const map<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return std::lexicographical_compare_three_way( + __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way); +} + +#endif // #if _LIBCPP_STD_VER <= 17 + template inline _LIBCPP_INLINE_VISIBILITY void @@ -2270,6 +2297,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 @@ -2315,6 +2344,20 @@ return !(__y < __x); } +#else // #if _LIBCPP_STD_VER <= 17 + +template +inline _LIBCPP_HIDE_FROM_ABI +__synth_three_way_result> +operator<=>(const multimap<_Key, _Tp, _Compare, _Allocator>& __x, + const multimap<_Key, _Tp, _Compare, _Allocator>& __y) +{ + return std::lexicographical_compare_three_way( + __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way); +} + +#endif // #if _LIBCPP_STD_VER <= 17 + template inline _LIBCPP_INLINE_VISIBILITY void diff --git a/libcxx/test/libcxx/containers/associative/map/compare.three_way.pass.cpp b/libcxx/test/libcxx/containers/associative/map/compare.three_way.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/containers/associative/map/compare.three_way.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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 map + +// template +// synth-three-way-result> +// operator<=>(const map& x, +// const map& y); + +#include +#include + +#include "test_container_comparisons.h" + +int main(int, char**) { + assert(test_ordered_map_container_spaceship()); + // `std::map` is not constexpr, so no `static_assert` test here. + return 0; +} diff --git a/libcxx/test/libcxx/containers/associative/multimap/compare.three_way.pass.cpp b/libcxx/test/libcxx/containers/associative/multimap/compare.three_way.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/libcxx/containers/associative/multimap/compare.three_way.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// 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 multimap + +// template +// synth-three-way-result> +// operator<=>(const multimap& x, +// const multimap& y); + +#include +#include + +#include "test_container_comparisons.h" + +int main(int, char**) { + assert(test_ordered_map_container_spaceship()); + // `std::multimap` 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 @@ -81,4 +81,128 @@ return true; } +// Implementation detail of `test_ordered_map_container_spaceship` +template