]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multimap/insert/hint.cc
1 // Copyright (C) 2013-2016 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++11" }
20 // Insert with hint, specific to this library implementation.
23 #include <unordered_map>
24 #include <testsuite_hooks.h>
28 bool test
__attribute__((unused
)) = true;
30 typedef std::unordered_multimap
<int, int> Map
;
31 typedef typename
Map::value_type Pair
;
35 auto it1
= m
.insert(Pair(0, 0));
36 VERIFY( it1
!= m
.end() );
37 VERIFY( it1
->first
== 0 );
38 VERIFY( it1
->second
== 0 );
40 auto it2
= m
.insert(it1
, Pair(0, 2));
41 VERIFY( it2
!= m
.end() );
43 VERIFY( it2
->second
== 2 );
44 VERIFY( it2
== std::next(it1
) );
47 it2
= m
.insert(it1
, p
);
48 VERIFY( it2
== std::next(it1
) );
53 std::size_t operator()(int val
) const
59 bool test
__attribute__((unused
)) = true;
61 typedef std::unordered_multimap
<int, int, hasher
> Map
;
62 typedef typename
Map::value_type Pair
;
66 auto it1
= m
.insert(Pair(0, 0));
67 auto it2
= m
.insert(it1
, Pair(1, 0));
68 VERIFY( m
.bucket(it1
->first
) == m
.bucket(it2
->first
) );
69 VERIFY( m
.bucket_size(m
.bucket(it1
->first
)) == 2 );
71 auto it3
= m
.insert(it2
, Pair(2, 0));
72 VERIFY( m
.bucket(it3
->first
) != m
.bucket(it2
->first
) );
73 VERIFY( m
.bucket_size(m
.bucket(it3
->first
)) == 1 );
75 auto it4
= m
.insert(it1
, Pair(0, 1));
76 VERIFY( it4
== std::next(it1
) );
77 VERIFY( m
.bucket_size(m
.bucket(it1
->first
)) == 3 );
78 VERIFY( m
.bucket_size(m
.bucket(it3
->first
)) == 1 );
81 it4
= m
.insert(it2
, p
);
82 VERIFY( it4
== std::next(it2
) );
83 VERIFY( m
.bucket_size(m
.bucket(it1
->first
)) == 4 );
84 auto range
= m
.equal_range(0);
85 VERIFY( std::distance(range
.first
, range
.second
) == 2 );
86 range
= m
.equal_range(1);
87 VERIFY( std::distance(range
.first
, range
.second
) == 2 );
92 bool test
__attribute__((unused
)) = true;
94 typedef std::unordered_multimap
<int, int> Map
;
95 typedef typename
Map::value_type Pair
;
99 auto it1
= m
.insert(Pair(0, 0));
100 VERIFY( it1
!= m
.end() );
101 VERIFY( it1
->first
== 0 );
102 VERIFY( it1
->second
== 0 );
104 auto it2
= m
.emplace_hint(it1
, std::piecewise_construct
,
107 VERIFY( it2
!= m
.end() );
108 VERIFY( it2
!= it1
);
109 VERIFY( it2
->second
== 2 );
110 VERIFY( it2
== std::next(it1
) );
113 it2
= m
.emplace_hint(it1
, p
);
114 VERIFY( it2
== std::next(it1
) );