[libc++][spaceship] Implement operator<=> for deque

Based on https://reviews.llvm.org/D132312
Dependes on https://reviews.llvm.org/D132312

Reviewed By: #libc, Mordante, philnik

Spies: philnik, Mordante, yaxunl, libcxx-commits

Differential Revision: https://reviews.llvm.org/D144821
This commit is contained in:
Hristo Hristov 2023-03-03 13:35:07 +01:00 committed by Nikolas Klauser
parent 4d59ffb0d1
commit 2ff646f554
3 changed files with 50 additions and 6 deletions

View File

@ -36,7 +36,7 @@ Section,Description,Dependencies,Assignee,Complete
| `[string.cmp] <https://wg21.link/string.cmp>`_,| `basic_string <https://reviews.llvm.org/D131421>`_,None,Mark de Wever,|Complete|
| `[string.view.comparison] <https://wg21.link/string.view.comparison>`_,| `basic_string_view <https://reviews.llvm.org/D130295>`_,None,Mark de Wever,|Complete|
| `[array.syn] <https://wg21.link/array.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| `array <https://reviews.llvm.org/D132265>`_,[expos.only.func],Adrian Vogelsgesang,|In Progress|
| `[deque.syn] <https://wg21.link/deque.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| deque,[expos.only.func],Unassigned,|Not Started|
| `[deque.syn] <https://wg21.link/deque.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| deque <https://reviews.llvm.org/D144821>,[expos.only.func],Hristo Hristov,|Complete|
| `[forward.list.syn] <https://wg21.link/forward.list.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| forward_list,[expos.only.func],Unassigned,|Not Started|
| `[list.syn] <https://wg21.link/list.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| `list <https://reviews.llvm.org/D132312>`_,[expos.only.func],Adrian Vogelsgesang,|Complete|
| `[vector.syn] <https://wg21.link/vector.syn>`_ (`general <https://wg21.link/container.opt.reqmts>`_),| `vector <https://reviews.llvm.org/D132268>`_,[expos.only.func],Adrian Vogelsgesang,|In Progress|

1 Section Description Dependencies Assignee Complete
36 | `[counted.iter.cmp] <https://wg21.link/counted.iter.cmp>`_ | counted_iterator None Unassigned |Not Started|
37 | `[range.iota.iterator] <https://wg21.link/range.iota.iterator>`_ | `ranges::iota_view::iterator <https://reviews.llvm.org/D110774>`_ [concepts.cmp] Arthur O'Dwyer |Complete|
38 | `[range.transform.iterator] <https://wg21.link/range.transform.iterator>`_ | `ranges::transform_view::iterator <https://reviews.llvm.org/D110774>`_ [concepts.cmp] Arthur O'Dwyer |Complete|
39 | `[range.elements.iterator] <https://wg21.link/range.elements.iterator>`_ | ranges::elements_view::iterator [concepts.cmp] Hui Xie |Complete|
40 | `[time.duration.comparisons] <https://wg21.link/time.duration.comparisons>`_ chrono::duration None Mark de Wever |Not Started|
41 | `[time.point.comparisons] <https://wg21.link/time.point.comparisons>`_ chrono::time_point None Mark de Wever |Not Started|
42 | `[time.cal.day.nonmembers] <https://wg21.link/time.cal.day.nonmembers>`_ | `[time.cal.month.nonmembers] <https://wg21.link/time.cal.month.nonmembers>`_ | `[time.cal.year.nonmembers] <https://wg21.link/time.cal.year.nonmembers>`_ | `[time.cal.md.nonmembers] <https://wg21.link/time.cal.md.nonmembers>`_ | `[time.cal.mdlast] <https://wg21.link/time.cal.mdlast>`_ | `[time.cal.ym.nonmembers] <https://wg21.link/time.cal.ym.nonmembers>`_ | `[time.cal.ymd.nonmembers] <https://wg21.link/time.cal.ymd.nonmembers>`_ | `[time.cal.ymdlast.nonmembers] <https://wg21.link/time.cal.ymdlast.nonmembers>`_ | `chrono::day <https://reviews.llvm.org/D129887>`_ | `chrono::month <https://reviews.llvm.org/D129887>`_ | `chrono::year <https://reviews.llvm.org/D129887>`_ | `chrono::month_day <https://reviews.llvm.org/D129887>`_ | `chrono::month_day_last <https://reviews.llvm.org/D129887>`_ | `chrono::year_month <https://reviews.llvm.org/D129887>`_ | `chrono::year_month_day <https://reviews.llvm.org/D129887>`_ | `chrono::year_month_day_last <https://reviews.llvm.org/D129887>`_ None Mark de Wever |Complete|

View File

@ -134,15 +134,18 @@ template <class InputIterator, class Allocator = allocator<typename iterator_tra
template <class T, class Allocator>
bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
template <class T, class Allocator>
bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
template <class T, class Allocator>
bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
template <class T, class Allocator>
bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
template <class T, class Allocator>
bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
template <class T, class Allocator>
bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y); // removed in C++20
template<class T, class Allocator>
synth-three-way-result<T> operator<=>(const deque<T, Allocator>& x,
const deque<T, Allocator>& y); // since C++20
// specialized algorithms:
template <class T, class Allocator>
@ -165,6 +168,7 @@ template <class T, class Allocator, class Predicate>
#include <__algorithm/equal.h>
#include <__algorithm/fill_n.h>
#include <__algorithm/lexicographical_compare.h>
#include <__algorithm/lexicographical_compare_three_way.h>
#include <__algorithm/min.h>
#include <__algorithm/remove.h>
#include <__algorithm/remove_if.h>
@ -2342,6 +2346,8 @@ operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
#if _LIBCPP_STD_VER <= 17
template <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI
bool
@ -2382,6 +2388,19 @@ operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
return !(__y < __x);
}
#else // _LIBCPP_STD_VER <= 17
template<class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI
__synth_three_way_result<_Tp>
operator<=>(const deque<_Tp, _Allocator>& __x, const deque<_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 <class _Tp, class _Allocator>
inline _LIBCPP_HIDE_FROM_ABI
void

View File

@ -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
// <deque>
// template<class T, class Allocator>
// synth-three-way-result<T> operator<=>(const deque<T, Allocator>& x,
// const deque<T, Allocator>& y);
#include <cassert>
#include <deque>
#include "test_container_comparisons.h"
int main(int, char**) {
assert(test_ordered_container_spaceship<std::deque>());
// `std::deque` is not constexpr, so no `static_assert` test here.
return 0;
}