]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multimap/operators/cmp_c++20.cc
1 // Copyright (C) 2020-2022 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::multimap
<int, int> c1
{ {1,1}, {2,1}, {3,1} };
28 std::multimap
<int, int> c2
{ {1,1}, {2,1}, {3,1}, {4,1} };
29 std::multimap
<int, int> c3
{ {1,1}, {2,1}, {3,2} };
31 VERIFY( std::is_eq(c1
<=> c1
) );
33 VERIFY( std::is_lt(c1
<=> c2
) );
35 VERIFY( std::is_lt(c1
<=> c3
) );
37 VERIFY( std::is_lt(c2
<=> c3
) );
39 static_assert( std::totally_ordered
<std::multimap
<int, int>> );
41 static_assert( std::three_way_comparable
<std::multimap
<int, int>,
42 std::strong_ordering
> );
43 static_assert( ! std::three_way_comparable
<std::multimap
<int, float>,
44 std::strong_ordering
> );
45 static_assert( ! std::three_way_comparable
<std::multimap
<int, float>,
46 std::weak_ordering
> );
47 static_assert( std::three_way_comparable
<std::multimap
<int, float>,
48 std::partial_ordering
> );
52 bool operator==(E
) { return true; }
54 static_assert( ! std::totally_ordered
<std::multimap
<int, E
>> );
55 static_assert( ! std::three_way_comparable
<E
> );
56 static_assert( ! std::three_way_comparable
<std::multimap
<int, E
>> );
66 bool operator==(W rhs
) const noexcept
67 { return (value
| 1) == (rhs
.value
| 1); }
70 operator<=>(W rhs
) const noexcept
71 { return (value
| 1) <=> (rhs
.value
| 1); }
74 static_assert( std::totally_ordered
<std::multimap
<int, W
>> );
76 using P
= std::pair
<const W
, W
>;
77 std::multimap
<W
, W
> c1
{ P
{1,1}, P
{2,2}, P
{3,3} }, c2
{ P
{1,0}, P
{3,2}, P
{3,3} };
78 static_assert( std::same_as
<decltype(c1
<=> c1
), std::weak_ordering
> );
80 VERIFY( std::is_eq(c1
<=> c2
) );
90 bool operator<(L rhs
) const noexcept
{ return value
< rhs
.value
; }
93 static_assert( std::totally_ordered
<std::multimap
<int, L
>> );
95 using P
= std::pair
<const L
, L
>;
96 std::multimap
<L
, L
> c
{ P
{1,1}, P
{2,2}, P
{3,3} }, d
{ P
{1,1}, P
{2,2}, P
{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::multimap
<int, int>::iterator
> );
103 static_assert( ! std::three_way_comparable
<std::multimap
<int, int>::iterator
> );