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 @@ -38,7 +38,7 @@ | `[array.syn] `_ (`general `_),| `array `_,[expos.only.func],Adrian Vogelsgesang,|In Progress| | `[deque.syn] `_ (`general `_),| deque,[expos.only.func],Unassigned,|Not Started| | `[forward.list.syn] `_ (`general `_),| forward_list,[expos.only.func],Unassigned,|Not Started| -| `[list.syn] `_ (`general `_),| list,[expos.only.func],Unassigned,|Not Started| +| `[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| diff --git a/libcxx/include/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -155,15 +155,18 @@ template bool operator==(const list& x, const list& y); template - bool operator< (const list& x, const list& y); + bool operator< (const list& x, const list& y); // removed in C++20 template - bool operator!=(const list& x, const list& y); + bool operator!=(const list& x, const list& y); // removed in C++20 template - bool operator> (const list& x, const list& y); + bool operator> (const list& x, const list& y); // removed in C++20 template - bool operator>=(const list& x, const list& y); + bool operator>=(const list& x, const list& y); // removed in C++20 template - bool operator<=(const list& x, const list& y); + bool operator<=(const list& x, const list& y); // removed in C++20 +template + synth-three-way-result operator<=>(const list& x, + const list& y); // since C++20 template void swap(list& x, list& y) @@ -171,10 +174,10 @@ template typename list::size_type - erase(list& c, const U& value); // C++20 + erase(list& c, const U& value); // since C++20 template typename list::size_type - erase_if(list& c, Predicate pred); // C++20 + erase_if(list& c, Predicate pred); // since C++20 } // std @@ -183,6 +186,7 @@ #include <__algorithm/comp.h> #include <__algorithm/equal.h> #include <__algorithm/lexicographical_compare.h> +#include <__algorithm/lexicographical_compare_three_way.h> #include <__algorithm/min.h> #include <__assert> // all public C++ headers provide the assertion handler #include <__config> @@ -2289,6 +2293,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 @@ -2329,6 +2335,18 @@ return !(__y < __x); } +#else // _LIBCPP_STD_VER <= 17 + +template +__synth_three_way_result<_Tp> +_LIBCPP_HIDE_FROM_ABI operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y) +{ + return lexicographical_compare_three_way( + __x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way); +} + +#endif // _LIBCPP_STD_VER <= 17 + template inline _LIBCPP_INLINE_VISIBILITY void diff --git a/libcxx/test/std/containers/sequences/list/compare.three_way.pass.cpp b/libcxx/test/std/containers/sequences/list/compare.three_way.pass.cpp new file mode 100644 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/compare.three_way.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 + +// + +// template constexpr +// synth-three-way-result +// operator<=>(const list& x, const list& y); + +#include +#include + +#include "test_container_comparisons.h" + +int main() { + assert(test_ordered_container_spaceship()); + // `std::list` 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 new file mode 100644 --- /dev/null +++ b/libcxx/test/support/test_container_comparisons.h @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// +// Utility functions to test comparisons on containers. + +#include "test_comparisons.h" + +// Implementation detail of `test_ordered_container_spaceship` +template