1 // Copyright (C) 2021-2025 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-do run { target c++20 } }
20 #include <unordered_set>
21 #include <testsuite_hooks.h>
25 typedef void is_transparent
;
27 bool operator()(int i
, long l
) const { return i
== l
; }
28 bool operator()(long l
, int i
) const { return l
== i
; }
29 bool operator()(int i
, int j
) const { ++count
; return i
== j
; }
38 typedef void is_transparent
;
40 std::size_t operator()(int i
) const { ++count
; return i
; }
41 std::size_t operator()(long l
) const { return l
; }
48 using test_type
= std::unordered_multiset
<int, Hash
, Equal
>;
50 test_type x
{ 1, 3, 3, 5 };
51 const test_type
& cx
= x
;
59 VERIFY( x
.contains(1L) );
62 VERIFY( it
!= x
.end() && *it
== 1 );
64 VERIFY( it
== x
.end() );
66 auto cit
= cx
.find(3L);
67 VERIFY( cit
!= cx
.end() && *cit
== 3 );
69 VERIFY( cit
== cx
.end() );
71 VERIFY( Hash::count
== 0 );
72 VERIFY( Equal::count
== 0 );
74 static_assert(std::is_same
<decltype(it
), test_type::iterator
>::value
,
75 "find returns iterator");
76 static_assert(std::is_same
<decltype(cit
), test_type::const_iterator
>::value
,
77 "const find returns const_iterator");
91 auto cn
= cx
.count(3L);
96 VERIFY( Hash::count
== 0 );
97 VERIFY( Equal::count
== 0 );
106 auto it
= x
.equal_range(1L);
107 VERIFY( it
.first
!= it
.second
&& *it
.first
== 1 );
108 it
= x
.equal_range(2L);
109 VERIFY( it
.first
== it
.second
&& it
.first
== x
.end() );
111 auto cit
= cx
.equal_range(3L);
112 VERIFY( cit
.first
!= cit
.second
&& *cit
.first
== 3 );
113 VERIFY( std::distance(cit
.first
, cit
.second
) == 2 );
114 cit
= cx
.equal_range(2L);
115 VERIFY( cit
.first
== cit
.second
&& cit
.first
== cx
.end() );
117 VERIFY( Hash::count
== 0 );
118 VERIFY( Equal::count
== 0 );
120 using pair
= std::pair
<test_type::iterator
, test_type::iterator
>;
121 static_assert(std::is_same
<decltype(it
), pair
>::value
,
122 "equal_range returns pair<iterator, iterator>");
123 using cpair
= std::pair
<test_type::const_iterator
, test_type::const_iterator
>;
124 static_assert(std::is_same
<decltype(cit
), cpair
>::value
,
125 "const equal_range returns pair<const_iterator, const_iterator>");