1 // Copyright (C) 2013-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++11 } }
20 // Insert with hint, specific to this library implementation.
23 #include <unordered_map>
24 #include <testsuite_hooks.h>
28 typedef std::unordered_multimap
<int, int> Map
;
29 typedef typename
Map::value_type Pair
;
34 auto it1
= m
.insert(Pair(0, 0));
35 VERIFY( it1
!= m
.end() );
36 VERIFY( it1
->first
== 0 );
37 VERIFY( it1
->second
== 0 );
39 auto it2
= m
.insert(it1
, Pair(0, 2));
40 VERIFY( it2
!= m
.end() );
42 VERIFY( it2
->second
== 2 );
43 VERIFY( it2
== std::next(it1
) );
46 it2
= m
.insert(it1
, p
);
47 VERIFY( it2
== std::next(it1
) );
52 std::size_t operator()(int val
) const
58 typedef std::unordered_multimap
<int, int, hasher
> Map
;
59 typedef typename
Map::value_type Pair
;
64 auto it1
= m
.insert(Pair(0, 0));
65 auto it2
= m
.insert(it1
, Pair(1, 0));
66 VERIFY( m
.bucket(it1
->first
) == m
.bucket(it2
->first
) );
67 VERIFY( m
.bucket_size(m
.bucket(it1
->first
)) == 2 );
69 auto it3
= m
.insert(it2
, Pair(2, 0));
70 VERIFY( m
.bucket(it3
->first
) != m
.bucket(it2
->first
) );
71 VERIFY( m
.bucket_size(m
.bucket(it3
->first
)) == 1 );
73 auto it4
= m
.insert(it1
, Pair(0, 1));
74 VERIFY( it4
== std::next(it1
) );
75 VERIFY( m
.bucket_size(m
.bucket(it1
->first
)) == 3 );
76 VERIFY( m
.bucket_size(m
.bucket(it3
->first
)) == 1 );
79 it4
= m
.insert(it2
, p
);
80 VERIFY( it4
== std::next(it2
) );
81 VERIFY( m
.bucket_size(m
.bucket(it1
->first
)) == 4 );
82 auto range
= m
.equal_range(0);
83 VERIFY( std::distance(range
.first
, range
.second
) == 2 );
84 range
= m
.equal_range(1);
85 VERIFY( std::distance(range
.first
, range
.second
) == 2 );
90 typedef std::unordered_multimap
<int, int> Map
;
91 typedef typename
Map::value_type Pair
;
96 auto it1
= m
.insert(Pair(0, 0));
97 VERIFY( it1
!= m
.end() );
98 VERIFY( it1
->first
== 0 );
99 VERIFY( it1
->second
== 0 );
101 auto it2
= m
.emplace_hint(it1
, std::piecewise_construct
,
104 VERIFY( it2
!= m
.end() );
105 VERIFY( it2
!= it1
);
106 VERIFY( it2
->second
== 2 );
107 VERIFY( it2
== std::next(it1
) );
110 it2
= m
.emplace_hint(it1
, p
);
111 VERIFY( it2
== std::next(it1
) );