]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multiset/operations/1.cc
1 // Copyright (C) 2021-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++20" }
19 // { dg-do run { target c++20 } }
21 #include <unordered_set>
22 #include <testsuite_hooks.h>
26 typedef void is_transparent
;
28 bool operator()(int i
, long l
) const { return i
== l
; }
29 bool operator()(long l
, int i
) const { return l
== i
; }
30 bool operator()(int i
, int j
) const { ++count
; return i
== j
; }
39 typedef void is_transparent
;
41 std::size_t operator()(int i
) const { ++count
; return i
; }
42 std::size_t operator()(long l
) const { return l
; }
49 using test_type
= std::unordered_multiset
<int, Hash
, Equal
>;
51 test_type x
{ 1, 3, 3, 5 };
52 const test_type
& cx
= x
;
60 VERIFY( x
.contains(1L) );
63 VERIFY( it
!= x
.end() && *it
== 1 );
65 VERIFY( it
== x
.end() );
67 auto cit
= cx
.find(3L);
68 VERIFY( cit
!= cx
.end() && *cit
== 3 );
70 VERIFY( cit
== cx
.end() );
72 VERIFY( Hash::count
== 0 );
73 VERIFY( Equal::count
== 0 );
75 static_assert(std::is_same
<decltype(it
), test_type::iterator
>::value
,
76 "find returns iterator");
77 static_assert(std::is_same
<decltype(cit
), test_type::const_iterator
>::value
,
78 "const find returns const_iterator");
92 auto cn
= cx
.count(3L);
97 VERIFY( Hash::count
== 0 );
98 VERIFY( Equal::count
== 0 );
107 auto it
= x
.equal_range(1L);
108 VERIFY( it
.first
!= it
.second
&& *it
.first
== 1 );
109 it
= x
.equal_range(2L);
110 VERIFY( it
.first
== it
.second
&& it
.first
== x
.end() );
112 auto cit
= cx
.equal_range(3L);
113 VERIFY( cit
.first
!= cit
.second
&& *cit
.first
== 3 );
114 VERIFY( std::distance(cit
.first
, cit
.second
) == 2 );
115 cit
= cx
.equal_range(2L);
116 VERIFY( cit
.first
== cit
.second
&& cit
.first
== cx
.end() );
118 VERIFY( Hash::count
== 0 );
119 VERIFY( Equal::count
== 0 );
121 using pair
= std::pair
<test_type::iterator
, test_type::iterator
>;
122 static_assert(std::is_same
<decltype(it
), pair
>::value
,
123 "equal_range returns pair<iterator, iterator>");
124 using cpair
= std::pair
<test_type::const_iterator
, test_type::const_iterator
>;
125 static_assert(std::is_same
<decltype(cit
), cpair
>::value
,
126 "const equal_range returns pair<const_iterator, const_iterator>");