From: Adrian Vogelsgesang Date: Sat, 20 Aug 2022 20:27:32 +0000 (-0700) Subject: [libc++][spaceship] Implement `operator<=>` for `list` X-Git-Tag: upstream/17.0.6~16290 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5a84ae09ab0bb59e43c5b4388fc1fe61cffec23;p=platform%2Fupstream%2Fllvm.git [libc++][spaceship] Implement `operator<=>` for `list` Implements part of P1614R2 "The Mothership has Landed" Differential Revision: https://reviews.llvm.org/D132312 --- diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv index e09ef9e..8baba5e 100644 --- a/libcxx/docs/Status/SpaceshipProjects.csv +++ b/libcxx/docs/Status/SpaceshipProjects.csv @@ -38,7 +38,7 @@ Section,Description,Dependencies,Assignee,Complete | `[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 index 0f02c99..c0fe2f9 100644 --- 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 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 @@ template #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 @@ operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 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,19 @@ operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) return !(__y < __x); } +#else // _LIBCPP_STD_VER <= 17 + +template +inline _LIBCPP_HIDE_FROM_ABI +__synth_three_way_result<_Tp> +operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y) +{ + return std::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 index 0000000..592067b --- /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(int, char**) { + 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 index 0000000..d4659bd --- /dev/null +++ b/libcxx/test/support/test_container_comparisons.h @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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. + +#ifndef TEST_CONTAINER_COMPARISONS +#define TEST_CONTAINER_COMPARISONS + +#include "test_comparisons.h" + +// Implementation detail of `test_ordered_container_spaceship` +template