diff --git a/libcxx/include/stack b/libcxx/include/stack --- a/libcxx/include/stack +++ b/libcxx/include/stack @@ -89,6 +89,9 @@ bool operator>=(const stack& x, const stack& y); template bool operator<=(const stack& x, const stack& y); +template + compare_three_way_result_t + operator<=>(const stack& x, const stack& y); // since C++20 template void swap(stack& x, stack& y) @@ -346,6 +349,16 @@ return !(__y < __x); } +#if _LIBCPP_STD_VER >= 20 + +template +_LIBCPP_HIDE_FROM_ABI compare_three_way_result_t<_Container> +operator<=>(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y) { + return __x.__get_container() <=> __y.__get_container(); +} + +#endif + template 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 --- /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 + +// + +// template +// compare_three_way_result_t +// operator<=>(const stack& x, const stack& y); + +#include +#include +#include +#include +#include + +#include "nasty_containers.h" +#include "test_container_comparisons.h" + +int main(int, char**) { + assert((test_ordered_container_adaptor_spaceship())); + assert((test_ordered_container_adaptor_spaceship())); + assert((test_ordered_container_adaptor_spaceship())); + assert((test_sequence_container_adaptor_spaceship())); + assert((test_sequence_container_adaptor_spaceship())); + // `std::stack` is not constexpr, so no `static_assert` test here. + return 0; +}