]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/deque/operators/cmp_c++20.cc
1 // Copyright (C) 2020-2023 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++20 } }
21 #include <testsuite_hooks.h>
26 std::deque
<int> c1
{ 1, 2, 3 }, c2
{ 1, 2, 3, 4 }, c3
{ 1, 2, 4 };
28 VERIFY( std::is_eq(c1
<=> c1
) );
30 VERIFY( std::is_lt(c1
<=> c2
) );
32 VERIFY( std::is_lt(c1
<=> c3
) );
34 VERIFY( std::is_lt(c2
<=> c3
) );
36 static_assert( std::totally_ordered
<std::deque
<int>> );
38 static_assert( std::three_way_comparable
<std::deque
<int>,
39 std::strong_ordering
> );
40 static_assert( ! std::three_way_comparable
<std::deque
<float>,
41 std::strong_ordering
> );
42 static_assert( ! std::three_way_comparable
<std::deque
<float>,
43 std::weak_ordering
> );
44 static_assert( std::three_way_comparable
<std::deque
<float>,
45 std::partial_ordering
> );
49 bool operator==(E
) { return true; }
51 static_assert( ! std::totally_ordered
<std::deque
<E
>> );
52 static_assert( ! std::three_way_comparable
<E
> );
53 static_assert( ! std::three_way_comparable
<std::deque
<E
>> );
63 bool operator==(W rhs
) const noexcept
64 { return (value
| 1) == (rhs
.value
| 1); }
67 operator<=>(W rhs
) const noexcept
68 { return (value
| 1) <=> (rhs
.value
| 1); }
71 static_assert( std::totally_ordered
<std::deque
<W
>> );
73 std::deque
<W
> c1
{ {1}, {2}, {3} }, c2
{ {0}, {3}, {3} };
74 static_assert( std::same_as
<decltype(c1
<=> c1
), std::weak_ordering
> );
76 VERIFY( std::is_eq(c1
<=> c2
) );
86 bool operator==(P rhs
) const noexcept
88 if (value
< 0 || rhs
.value
< 0)
90 return value
== rhs
.value
;
94 operator<=>(P rhs
) const noexcept
96 if (value
< 0 || rhs
.value
< 0)
97 return std::partial_ordering::unordered
;
98 return value
<=> rhs
.value
;
102 static_assert( std::totally_ordered
<std::deque
<P
>> );
104 std::deque
<P
> c
{ {1}, {2}, {-3} };
105 static_assert( std::three_way_comparable
<P
> );
106 static_assert( std::same_as
<decltype(c
<=> c
), std::partial_ordering
> );
107 VERIFY( (c
<=> c
) == std::partial_ordering::unordered
);
117 bool operator<(L rhs
) const noexcept
{ return value
< rhs
.value
; }
120 static_assert( std::totally_ordered
<std::deque
<L
>> );
122 std::deque
<L
> c
{ {1}, {2}, {3} }, d
{ {1}, {2}, {3}, {4} };
123 static_assert( std::same_as
<decltype(c
<=> c
), std::weak_ordering
> );
124 VERIFY( std::is_lt(c
<=> d
) );
130 // deque iterators are random access, so should support <=>
132 std::deque
<int> c
{ 1, 2, 3 };
133 VERIFY( c
.begin() == c
.cbegin() );
134 VERIFY( std::is_eq(c
.begin() <=> c
.cbegin()) );
136 VERIFY( c
.begin() < c
.end() );
137 VERIFY( std::is_lt(c
.begin() <=> c
.end()) );
139 VERIFY( c
.begin() < c
.cend() );
140 VERIFY( std::is_lt(c
.begin() <=> c
.cend()) );
142 VERIFY( c
.crbegin() == c
.rbegin() );
143 VERIFY( std::is_eq(c
.crbegin() <=> c
.rbegin()) );
145 VERIFY( c
.rend() > c
.rbegin() );
146 VERIFY( std::is_gt(c
.rend() <=> c
.rbegin()) );
148 static_assert( std::same_as
<decltype(c
.begin() <=> c
.begin()),
149 std::strong_ordering
> );