annotate libstdc++-v3/testsuite/23_containers/deque/operators/cmp_c++20.cc @ 19:2b5abeee2509 default tip

update gcc11
author anatofuz
date Mon, 25 May 2020 07:50:57 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
1 // Copyright (C) 2020 Free Software Foundation, Inc.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
2 //
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
3 // This file is part of the GNU ISO C++ Library. This library is free
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
4 // software; you can redistribute it and/or modify it under the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
5 // terms of the GNU General Public License as published by the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
6 // Free Software Foundation; either version 3, or (at your option)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
7 // any later version.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
8
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
9 // This library is distributed in the hope that it will be useful,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
12 // GNU General Public License for more details.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
13
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
14 // You should have received a copy of the GNU General Public License along
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
15 // with this library; see the file COPYING3. If not see
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
16 // <http://www.gnu.org/licenses/>.
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
17
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
18 // { dg-options "-std=gnu++2a" }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
19 // { dg-do run { target c++2a } }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
20
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
21 #include <deque>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
22 #include <testsuite_hooks.h>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
23
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
24 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
25 test01()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
26 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
27 std::deque<int> c1{ 1, 2, 3 }, c2{ 1, 2, 3, 4 }, c3{ 1, 2, 4 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 VERIFY( c1 == c1 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 VERIFY( std::is_eq(c1 <=> c1) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 VERIFY( c1 < c2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 VERIFY( std::is_lt(c1 <=> c2) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 VERIFY( c1 < c3 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 VERIFY( std::is_lt(c1 <=> c3) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 VERIFY( c2 < c3 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 VERIFY( std::is_lt(c2 <=> c3) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 static_assert( std::totally_ordered<std::deque<int>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 static_assert( std::three_way_comparable<std::deque<int>,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40 std::strong_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 static_assert( ! std::three_way_comparable<std::deque<float>,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
42 std::strong_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
43 static_assert( ! std::three_way_comparable<std::deque<float>,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 std::weak_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 static_assert( std::three_way_comparable<std::deque<float>,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 std::partial_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 struct E
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50 bool operator==(E) { return true; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 static_assert( ! std::totally_ordered<std::deque<E>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 static_assert( ! std::three_way_comparable<E> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 static_assert( ! std::three_way_comparable<std::deque<E>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58 test02()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 struct W
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 int value = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 bool operator==(W rhs) const noexcept
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65 { return (value | 1) == (rhs.value | 1); }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 std::weak_ordering
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68 operator<=>(W rhs) const noexcept
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 { return (value | 1) <=> (rhs.value | 1); }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 static_assert( std::totally_ordered<std::deque<W>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 std::deque<W> c1{ {1}, {2}, {3} }, c2{ {0}, {3}, {3} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75 static_assert( std::same_as<decltype(c1 <=> c1), std::weak_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 VERIFY( c1 == c2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 VERIFY( std::is_eq(c1 <=> c2) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81 test03()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83 struct P
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85 int value = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87 bool operator==(P rhs) const noexcept
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89 if (value < 0 || rhs.value < 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 return false;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91 return value == rhs.value;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94 std::partial_ordering
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95 operator<=>(P rhs) const noexcept
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 if (value < 0 || rhs.value < 0)
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98 return std::partial_ordering::unordered;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99 return value <=> rhs.value;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 static_assert( std::totally_ordered<std::deque<P>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
104
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
105 std::deque<P> c{ {1}, {2}, {-3} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
106 static_assert( std::three_way_comparable<P> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
107 static_assert( std::same_as<decltype(c <=> c), std::partial_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
108 VERIFY( (c <=> c) == std::partial_ordering::unordered );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
109 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
110
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
111 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
112 test04()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
113 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
114 struct L
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
115 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
116 int value = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
117
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
118 bool operator<(L rhs) const noexcept { return value < rhs.value; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
119 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
120
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
121 static_assert( std::totally_ordered<std::deque<L>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
122
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
123 std::deque<L> c{ {1}, {2}, {3} }, d{ {1}, {2}, {3}, {4} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
124 static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
125 VERIFY( std::is_lt(c <=> d) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
126 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
127
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
128 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
129 test05()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
130 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
131 // deque iterators are random access, so should support <=>
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
132
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
133 std::deque<int> c{ 1, 2, 3 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
134 VERIFY( c.begin() == c.cbegin() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
135 VERIFY( std::is_eq(c.begin() <=> c.cbegin()) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
136
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
137 VERIFY( c.begin() < c.end() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
138 VERIFY( std::is_lt(c.begin() <=> c.end()) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
139
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
140 VERIFY( c.begin() < c.cend() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
141 VERIFY( std::is_lt(c.begin() <=> c.cend()) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
142
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
143 VERIFY( c.crbegin() == c.rbegin() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
144 VERIFY( std::is_eq(c.crbegin() <=> c.rbegin()) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
145
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
146 VERIFY( c.rend() > c.rbegin() );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
147 VERIFY( std::is_gt(c.rend() <=> c.rbegin()) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
148
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
149 static_assert( std::same_as<decltype(c.begin() <=> c.begin()),
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
150 std::strong_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
151 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
152
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
153 int
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
154 main()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
155 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
156 test01();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
157 test02();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
158 test03();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
159 test04();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
160 test05();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
161 }