diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-04-17 23:41:04 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-04-17 23:41:04 +0100 |
commit | bd2420f8faaf4bb33310e82f7dd45c5e33476c87 (patch) | |
tree | 195aaff3ff206340a940f18b91d19c5ae9e2c507 /libstdc++-v3/include/debug | |
parent | 3737ccc424c56a2cecff202dd79f88d28850eeb2 (diff) |
libstdc++: Add comparison operators to sequence containers
Some more C++20 changes from P1614R2, "The Mothership has Landed".
This implements <=> for sequence containers (and the __normal_iterator
and _Pointer_adapter class templates).
* include/bits/forward_list.h (forward_list): Define operator<=> and
remove redundant comparison operators for C++20.
* include/bits/stl_bvector.h (vector<bool, Alloc>): Likewise.
* include/bits/stl_deque.h (deque): Likewise.
* include/bits/stl_iterator.h (__normal_iterator): Likewise.
* include/bits/stl_list.h (list): Likewise.
* include/bits/stl_vector.h (vector): Likewise.
* include/debug/deque (__gnu_debug::deque): Likewise.
* include/debug/forward_list (__gnu_debug::forward_list): Likewise.
* include/debug/list (__gnu_debug::list): Likewise.
* include/debug/safe_iterator.h (__gnu_debug::_Safe_iterator):
Likewise.
* include/debug/vector (__gnu_debug::vector): Likewise.
* include/ext/pointer.h (__gnu_cxx::_Pointer_adapter): Define
operator<=> for C++20.
* testsuite/23_containers/deque/operators/cmp_c++20.cc: New test.
* testsuite/23_containers/forward_list/cmp_c++20.cc: New test.
* testsuite/23_containers/list/cmp_c++20.cc: New test.
* testsuite/23_containers/vector/bool/cmp_c++20.cc: New test.
* testsuite/23_containers/vector/cmp_c++20.cc: New test.
Diffstat (limited to 'libstdc++-v3/include/debug')
-rw-r--r-- | libstdc++-v3/include/debug/deque | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/forward_list | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/list | 7 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/safe_iterator.h | 21 | ||||
-rw-r--r-- | libstdc++-v3/include/debug/vector | 7 |
5 files changed, 50 insertions, 0 deletions
diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque index 8c6b4d14c2b..4d525bfc0aa 100644 --- a/libstdc++-v3/include/debug/deque +++ b/libstdc++-v3/include/debug/deque @@ -648,6 +648,12 @@ namespace __debug const deque<_Tp, _Alloc>& __rhs) { return __lhs._M_base() == __rhs._M_base(); } +#if __cpp_lib_three_way_comparison + template<typename _Tp, typename _Alloc> + constexpr __detail::__synth3way_t<_Tp> + operator<=>(const deque<_Tp, _Alloc>& __x, const deque<_Tp, _Alloc>& __y) + { return __x._M_base() <=> __y._M_base(); } +#else template<typename _Tp, typename _Alloc> inline bool operator!=(const deque<_Tp, _Alloc>& __lhs, @@ -677,6 +683,7 @@ namespace __debug operator>(const deque<_Tp, _Alloc>& __lhs, const deque<_Tp, _Alloc>& __rhs) { return __lhs._M_base() > __rhs._M_base(); } +#endif // three-way comparison template<typename _Tp, typename _Alloc> inline void diff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list index f0ff62c8cb1..2fd03e70499 100644 --- a/libstdc++-v3/include/debug/forward_list +++ b/libstdc++-v3/include/debug/forward_list @@ -838,6 +838,13 @@ namespace __debug const forward_list<_Tp, _Alloc>& __ly) { return __lx._M_base() == __ly._M_base(); } +#if __cpp_lib_three_way_comparison + template<typename _Tp, typename _Alloc> + constexpr __detail::__synth3way_t<_Tp> + operator<=>(const forward_list<_Tp, _Alloc>& __x, + const forward_list<_Tp, _Alloc>& __y) + { return __x._M_base() <=> __y._M_base(); } +#else template<typename _Tp, typename _Alloc> inline bool operator<(const forward_list<_Tp, _Alloc>& __lx, @@ -870,6 +877,7 @@ namespace __debug operator<=(const forward_list<_Tp, _Alloc>& __lx, const forward_list<_Tp, _Alloc>& __ly) { return !(__ly < __lx); } +#endif // three-way comparison /// See std::forward_list::swap(). template<typename _Tp, typename _Alloc> diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list index ee54ef27e57..6dd85741f81 100644 --- a/libstdc++-v3/include/debug/list +++ b/libstdc++-v3/include/debug/list @@ -864,6 +864,12 @@ namespace __debug const list<_Tp, _Alloc>& __rhs) { return __lhs._M_base() == __rhs._M_base(); } +#if __cpp_lib_three_way_comparison + template<typename _Tp, typename _Alloc> + constexpr __detail::__synth3way_t<_Tp> + operator<=>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) + { return __x._M_base() <=> __y._M_base(); } +#else template<typename _Tp, typename _Alloc> inline bool operator!=(const list<_Tp, _Alloc>& __lhs, @@ -893,6 +899,7 @@ namespace __debug operator>(const list<_Tp, _Alloc>& __lhs, const list<_Tp, _Alloc>& __rhs) { return __lhs._M_base() > __rhs._M_base(); } +#endif // three-way comparison template<typename _Tp, typename _Alloc> inline void diff --git a/libstdc++-v3/include/debug/safe_iterator.h b/libstdc++-v3/include/debug/safe_iterator.h index f746cca5fb3..687b844fd75 100644 --- a/libstdc++-v3/include/debug/safe_iterator.h +++ b/libstdc++-v3/include/debug/safe_iterator.h @@ -35,6 +35,9 @@ #include <debug/safe_base.h> #include <bits/stl_pair.h> #include <ext/type_traits.h> +#if __cplusplus > 201703L +# include <compare> +#endif #define _GLIBCXX_DEBUG_VERIFY_OPERANDS(_Lhs, _Rhs, _BadMsgId, _DiffMsgId) \ _GLIBCXX_DEBUG_VERIFY(!_Lhs._M_singular() && !_Rhs._M_singular(), \ @@ -469,6 +472,7 @@ namespace __gnu_debug return __lhs.base() == __rhs.base(); } +#if ! __cpp_lib_three_way_comparison friend bool operator!=(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -485,6 +489,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY_EQ_OPERANDS(__lhs, __rhs); return __lhs.base() != __rhs.base(); } +#endif // three-way comparison }; template<typename _Iterator, typename _Sequence> @@ -805,6 +810,21 @@ namespace __gnu_debug return *this; } +#if __cpp_lib_three_way_comparison + friend auto + operator<=>(const _Self& __lhs, const _Self& __rhs) noexcept + { + _GLIBCXX_DEBUG_VERIFY_REL_OPERANDS(__lhs, __rhs); + return __lhs.base() <=> __rhs.base(); + } + + friend auto + operator<=>(const _Self& __lhs, const _OtherSelf& __rhs) noexcept + { + _GLIBCXX_DEBUG_VERIFY_REL_OPERANDS(__lhs, __rhs); + return __lhs.base() <=> __rhs.base(); + } +#else friend bool operator<(const _Self& __lhs, const _Self& __rhs) _GLIBCXX_NOEXCEPT { @@ -860,6 +880,7 @@ namespace __gnu_debug _GLIBCXX_DEBUG_VERIFY_REL_OPERANDS(__lhs, __rhs); return __lhs.base() >= __rhs.base(); } +#endif // three-way comparison // _GLIBCXX_RESOLVE_LIB_DEFECTS // According to the resolution of DR179 not only the various comparison diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector index 96772f72643..4c08ab61ce8 100644 --- a/libstdc++-v3/include/debug/vector +++ b/libstdc++-v3/include/debug/vector @@ -731,6 +731,12 @@ namespace __debug const vector<_Tp, _Alloc>& __rhs) { return __lhs._M_base() == __rhs._M_base(); } +#if __cpp_lib_three_way_comparison + template<typename _Tp, typename _Alloc> + constexpr __detail::__synth3way_t<_Tp> + operator<=>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) + { return __x._M_base() <=> __y._M_base(); } +#else template<typename _Tp, typename _Alloc> inline bool operator!=(const vector<_Tp, _Alloc>& __lhs, @@ -760,6 +766,7 @@ namespace __debug operator>(const vector<_Tp, _Alloc>& __lhs, const vector<_Tp, _Alloc>& __rhs) { return __lhs._M_base() > __rhs._M_base(); } +#endif // three-way comparison template<typename _Tp, typename _Alloc> inline void |