]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/set/operators/cmp_c++20.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / set / operators / cmp_c++20.cc
CommitLineData
a945c346 1// Copyright (C) 2020-2024 Free Software Foundation, Inc.
93843da6
JW
2//
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)
7// any later version.
8
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.
13
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/>.
17
b9a2dce8 18// { dg-do run { target c++20 } }
93843da6
JW
19
20#include <set>
21#include <testsuite_hooks.h>
22
23void
24test01()
25{
26 std::set<int> c1{ 1, 2, 3 }, c2{ 1, 2, 3, 4 }, c3{ 1, 2, 4 };
27 VERIFY( c1 == c1 );
28 VERIFY( std::is_eq(c1 <=> c1) );
29 VERIFY( c1 < c2 );
30 VERIFY( std::is_lt(c1 <=> c2) );
31 VERIFY( c1 < c3 );
32 VERIFY( std::is_lt(c1 <=> c3) );
33 VERIFY( c2 < c3 );
34 VERIFY( std::is_lt(c2 <=> c3) );
35
36 static_assert( std::totally_ordered<std::set<int>> );
37
38 static_assert( std::three_way_comparable<std::set<int>,
39 std::strong_ordering> );
40 static_assert( ! std::three_way_comparable<std::set<float>,
41 std::strong_ordering> );
42 static_assert( ! std::three_way_comparable<std::set<float>,
43 std::weak_ordering> );
44 static_assert( std::three_way_comparable<std::set<float>,
45 std::partial_ordering> );
46
47 struct E
48 {
49 bool operator==(E) { return true; }
50 };
c123096c
JW
51 struct Cmp
52 {
53 bool operator()(E, E) const { return false; }
54 };
55 static_assert( ! std::totally_ordered<std::set<E, Cmp>> );
93843da6 56 static_assert( ! std::three_way_comparable<E> );
c123096c 57 static_assert( ! std::three_way_comparable<std::set<E, Cmp>> );
93843da6
JW
58}
59
60void
61test02()
62{
63 struct W
64 {
65 int value = 0;
66
67 bool operator==(W rhs) const noexcept
68 { return (value | 1) == (rhs.value | 1); }
69
70 std::weak_ordering
71 operator<=>(W rhs) const noexcept
72 { return (value | 1) <=> (rhs.value | 1); }
73 };
74
75 static_assert( std::totally_ordered<std::set<W>> );
76
77 std::set<W> c1{ {1}, {2}, {3} }, c2{ {0}, {3}, {3} };
78 static_assert( std::same_as<decltype(c1 <=> c1), std::weak_ordering> );
79 VERIFY( c1 == c2 );
80 VERIFY( std::is_eq(c1 <=> c2) );
81}
82
83void
84test04()
85{
86 struct L
87 {
88 int value = 0;
89
90 bool operator<(L rhs) const noexcept { return value < rhs.value; }
91 };
92
93 static_assert( std::totally_ordered<std::set<L>> );
94
95 std::set<L> c{ {1}, {2}, {3} }, d{ {1}, {2}, {3}, {4} };
96 static_assert( std::same_as<decltype(c <=> c), std::weak_ordering> );
97 VERIFY( std::is_lt(c <=> d) );
98}
99
100// Associative container iterators are not random access
101static_assert( ! std::totally_ordered<std::set<int>::iterator> );
102static_assert( ! std::three_way_comparable<std::set<int>::iterator> );
103
104int
105main()
106{
107 test01();
108 test02();
109 test04();
110}