annotate libstdc++-v3/testsuite/23_containers/multiset/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 <set>
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::multiset<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::multiset<int>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
38
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
39 static_assert( std::three_way_comparable<std::multiset<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::multiset<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::multiset<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::multiset<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::multiset<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::multiset<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::multiset<W>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
73
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
74 std::multiset<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 test04()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
82 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
83 struct L
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<(L rhs) const noexcept { return value < rhs.value; }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
88 };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
89
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
90 static_assert( std::totally_ordered<std::multiset<L>> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
91
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
92 std::multiset<L> c{ {1}, {2}, {3} }, d{ {1}, {2}, {3}, {4} };
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
93 static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
94 VERIFY( std::is_lt(c <=> d) );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
95 }
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
96
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
97 // Associative container iterators are not random access
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
98 static_assert( ! std::totally_ordered<std::multiset<int>::iterator> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
99 static_assert( ! std::three_way_comparable<std::multiset<int>::iterator> );
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
100
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
101 int
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
102 main()
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
103 {
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
104 test01();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
105 test02();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
106 test04();
2b5abeee2509 update gcc11
anatofuz
parents:
diff changeset
107 }