annotate libstdc++-v3/testsuite/23_containers/map/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 <map>
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::map<int, int> c1{ {1,1}, {2,1}, {3,1} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
28 std::map<int, int> c2{ {1,1}, {2,1}, {3,1}, {4,1} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
29 std::map<int, int> c3{ {1,1}, {2,1}, {3,2} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
30 VERIFY( c1 == c1 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
31 VERIFY( std::is_eq(c1 <=> c1) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
32 VERIFY( c1 < c2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
33 VERIFY( std::is_lt(c1 <=> c2) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
34 VERIFY( c1 < c3 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
35 VERIFY( std::is_lt(c1 <=> c3) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
36 VERIFY( c2 < c3 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
37 VERIFY( std::is_lt(c2 <=> c3) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 static_assert( std::totally_ordered<std::map<int, int>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
40
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
41 static_assert( std::three_way_comparable<std::map<int, int>,
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::map<int, float>,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
44 std::strong_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
45 static_assert( ! std::three_way_comparable<std::map<int, float>,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
46 std::weak_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
47 static_assert( std::three_way_comparable<std::map<int, float>,
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
48 std::partial_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
49
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
50 struct E
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
51 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
52 bool operator==(E) { return true; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
53 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
54 static_assert( ! std::totally_ordered<std::map<int, E>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
55 static_assert( ! std::three_way_comparable<E> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
56 static_assert( ! std::three_way_comparable<std::map<int, E>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
57 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
58
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
59 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
60 test02()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
61 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
62 struct W
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
63 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
64 int value = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
65
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
66 bool operator==(W rhs) const noexcept
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
67 { return (value | 1) == (rhs.value | 1); }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
68
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
69 std::weak_ordering
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
70 operator<=>(W rhs) const noexcept
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
71 { return (value | 1) <=> (rhs.value | 1); }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
72 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 static_assert( std::totally_ordered<std::map<int, W>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
75
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
76 using P = std::pair<const W, W>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
77 std::map<W, W> c1{ P{1,1}, P{2,2}, P{3,3} }, c2{ P{1,0}, P{3,2}, P{3,3} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
78 static_assert( std::same_as<decltype(c1 <=> c1), std::weak_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
79 VERIFY( c1 == c2 );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
80 VERIFY( std::is_eq(c1 <=> c2) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
81 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83 void
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
84 test04()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
85 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
86 struct L
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
87 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88 int value = 0;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 bool operator<(L rhs) const noexcept { return value < rhs.value; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93 static_assert( std::totally_ordered<std::map<int, L>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95 using P = std::pair<const L, L>;
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96 std::map<L, L> c{ P{1,1}, P{2,2}, P{3,3} }, d{ P{1,1}, P{2,2}, P{3,4} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98 VERIFY( std::is_lt(c <=> d) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 // Associative container iterators are not random access
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102 static_assert( ! std::totally_ordered<std::map<int, int>::iterator> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 static_assert( ! std::three_way_comparable<std::map<int, int>::iterator> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
104
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
105 int
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
106 main()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
107 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
108 test01();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
109 test02();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
110 test04();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
111 }