[libcxx-commits] [libcxx] ca7a041 - [libc++][spaceship] Implement `operator<=>` for `stack`
Hristo Hristov via libcxx-commits
libcxx-commits at lists.llvm.org
Fri Jun 9 21:37:43 PDT 2023
Author: Hristo Hristov
Date: 2023-06-10T07:37:36+03:00
New Revision: ca7a041626cdd79f9d7e9f8361676a46c4a3bba9
URL: https://github.com/llvm/llvm-project/commit/ca7a041626cdd79f9d7e9f8361676a46c4a3bba9
DIFF: https://github.com/llvm/llvm-project/commit/ca7a041626cdd79f9d7e9f8361676a46c4a3bba9.diff
LOG: [libc++][spaceship] Implement `operator<=>` for `stack`
Depends on D146066
Depends on D132268
Implements parts of P1614R2 `operator<=>` for `stack`
Reviewed By: #libc, Mordante
Differential Revision: https://reviews.llvm.org/D146094
Added:
libcxx/test/std/containers/container.adaptors/stack/compare.three_way.pass.cpp
Modified:
libcxx/docs/Status/SpaceshipProjects.csv
libcxx/include/stack
Removed:
################################################################################
diff --git a/libcxx/docs/Status/SpaceshipProjects.csv b/libcxx/docs/Status/SpaceshipProjects.csv
index d118db07edff9..d89acad556cde 100644
--- a/libcxx/docs/Status/SpaceshipProjects.csv
+++ b/libcxx/docs/Status/SpaceshipProjects.csv
@@ -47,7 +47,7 @@ Section,Description,Dependencies,Assignee,Complete
| `[associative.set.syn] <https://wg21.link/associative.set.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),"| multiset
| set",[expos.only.func],Hristo Hristov,|In Progress|
| `[queue.ops] <https://wg21.link/queue.ops>`_,| `queue <https://reviews.llvm.org/D146066>`_,None,Hristo Hristov,|Complete|
-| `[stack.ops] <https://wg21.link/stack.ops>`_,| `stack <https://reviews.llvm.org/D146094>`_,None,Hristo Hristov,|In Progress|
+| `[stack.ops] <https://wg21.link/stack.ops>`_,| `stack <https://reviews.llvm.org/D146094>`_,None,Hristo Hristov,|Complete|
| `[reverse.iter.cmp] <https://wg21.link/reverse.iter.cmp>`_,| `reverse_iterator <https://reviews.llvm.org/D113695>`_,None,Mikhail Maltsev,|Complete|
| `[move.iter.op.comp] <https://wg21.link/move.iter.op.comp>`_,| `move_iterator <https://reviews.llvm.org/D117656>`_,None,Arthur O'Dwyer,|Complete|
| `[counted.iter.cmp] <https://wg21.link/counted.iter.cmp>`_,| `counted_iterator <https://reviews.llvm.org/D106205>`_,None,Zoe Carver,|Complete|
diff --git a/libcxx/include/stack b/libcxx/include/stack
index d49aacb5f2c1d..c25642fa9896f 100644
--- a/libcxx/include/stack
+++ b/libcxx/include/stack
@@ -101,6 +101,9 @@ template <class T, class Container>
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
+template<class T, three_way_comparable Container>
+ compare_three_way_result_t<Container>
+ operator<=>(const stack<T, Container>& x, const stack<T, Container>& y); // since C++20
template <class T, class Container>
void swap(stack<T, Container>& x, stack<T, Container>& y)
@@ -400,6 +403,17 @@ operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
return !(__y < __x);
}
+#if _LIBCPP_STD_VER >= 20
+
+template <class _Tp, three_way_comparable _Container>
+_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container>
+operator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) {
+ // clang 16 bug: declaring `friend operator<=>` causes "use of overloaded operator '*' is ambiguous" errors
+ return __x.__get_container() <=> __y.__get_container();
+}
+
+#endif
+
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
__enable_if_t<__is_swappable<_Container>::value, void>
diff --git a/libcxx/test/std/containers/container.adaptors/stack/compare.three_way.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/compare.three_way.pass.cpp
new file mode 100644
index 0000000000000..1889b7c9b7324
--- /dev/null
+++ b/libcxx/test/std/containers/container.adaptors/stack/compare.three_way.pass.cpp
@@ -0,0 +1,33 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+
+// <stack>
+
+// template<class T, three_way_comparable Container>
+// compare_three_way_result_t<Container>
+// operator<=>(const stack<T, Container>& x, const stack<T, Container>& y);
+
+#include <cassert>
+#include <deque>
+#include <list>
+#include <stack>
+#include <vector>
+
+#include "nasty_containers.h"
+#include "test_container_comparisons.h"
+
+int main(int, char**) {
+ assert((test_sequence_container_adaptor_spaceship<std::stack, std::deque>()));
+ assert((test_sequence_container_adaptor_spaceship<std::stack, std::list>()));
+ assert((test_sequence_container_adaptor_spaceship<std::stack, std::vector>()));
+ assert((test_sequence_container_adaptor_spaceship<std::stack, nasty_list>()));
+ assert((test_sequence_container_adaptor_spaceship<std::stack, nasty_vector>()));
+ // `std::stack` is not constexpr, so no `static_assert` test here.
+ return 0;
+}
More information about the libcxx-commits
mailing list