]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multiset/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-options "-std=gnu++2a" }
19 // { dg-do run { target c++2a } }
22 #include <testsuite_hooks.h>
27 std::multiset
<int> c1
{ 1, 2, 3 }, c2
{ 1, 2, 3, 4 }, c3
{ 1, 2, 4 };
29 VERIFY( std::is_eq(c1
<=> c1
) );
31 VERIFY( std::is_lt(c1
<=> c2
) );
33 VERIFY( std::is_lt(c1
<=> c3
) );
35 VERIFY( std::is_lt(c2
<=> c3
) );
37 static_assert( std::totally_ordered
<std::multiset
<int>> );
39 static_assert( std::three_way_comparable
<std::multiset
<int>,
40 std::strong_ordering
> );
41 static_assert( ! std::three_way_comparable
<std::multiset
<float>,
42 std::strong_ordering
> );
43 static_assert( ! std::three_way_comparable
<std::multiset
<float>,
44 std::weak_ordering
> );
45 static_assert( std::three_way_comparable
<std::multiset
<float>,
46 std::partial_ordering
> );
50 bool operator==(E
) { return true; }
54 bool operator()(E
, E
) const { return false; }
56 static_assert( ! std::totally_ordered
<std::multiset
<E
, Cmp
>> );
57 static_assert( ! std::three_way_comparable
<E
> );
58 static_assert( ! std::three_way_comparable
<std::multiset
<E
, Cmp
>> );
68 bool operator==(W rhs
) const noexcept
69 { return (value
| 1) == (rhs
.value
| 1); }
72 operator<=>(W rhs
) const noexcept
73 { return (value
| 1) <=> (rhs
.value
| 1); }
76 static_assert( std::totally_ordered
<std::multiset
<W
>> );
78 std::multiset
<W
> c1
{ {1}, {2}, {3} }, c2
{ {0}, {3}, {3} };
79 static_assert( std::same_as
<decltype(c1
<=> c1
), std::weak_ordering
> );
81 VERIFY( std::is_eq(c1
<=> c2
) );
91 bool operator<(L rhs
) const noexcept
{ return value
< rhs
.value
; }
94 static_assert( std::totally_ordered
<std::multiset
<L
>> );
96 std::multiset
<L
> c
{ {1}, {2}, {3} }, d
{ {1}, {2}, {3}, {4} };
97 static_assert( std::same_as
<decltype(c
<=> c
), std::weak_ordering
> );
98 VERIFY( std::is_lt(c
<=> d
) );
101 // Associative container iterators are not random access
102 static_assert( ! std::totally_ordered
<std::multiset
<int>::iterator
> );
103 static_assert( ! std::three_way_comparable
<std::multiset
<int>::iterator
> );