]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multiset/insert/52476.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_multiset / insert / 52476.cc
1 // { dg-options "-std=gnu++11" }
2 //
3 // Copyright (C) 2012-2016 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <unordered_set>
21 #include <vector>
22 #include <algorithm>
23 #include <testsuite_hooks.h>
24
25 namespace
26 {
27 struct pair_hash
28 {
29 std::size_t
30 operator()(const std::pair<int, int>& p) const noexcept
31 { return std::hash<int>()(p.first); }
32 };
33
34 struct pair_equal_to
35 {
36 bool
37 operator()(const std::pair<int, int>& x,
38 const std::pair<int, int>& y) const noexcept
39 { return x.first == y.first; }
40 };
41 }
42
43 void test01()
44 {
45 using namespace std;
46 bool test __attribute__((unused)) = true;
47
48 unordered_multiset<pair<int, int>, pair_hash, pair_equal_to> mset;
49 vector<int> values;
50
51 size_t nb_bkts = mset.bucket_count();
52 int i = 0;
53 for (;; ++i)
54 {
55 mset.insert(make_pair(0, i));
56 if (mset.bucket_count() != nb_bkts)
57 // Container got rehash
58 break;
59 values.clear();
60 transform(mset.begin(), mset.end(), back_inserter(values),
61 [](const pair<int, int>& p) { return p.second; });
62 }
63
64 vector<int> rehash_values;
65 transform(mset.begin(), mset.end(), back_inserter(rehash_values),
66 [](const pair<int, int>& p) { return p.second; });
67 // Remove the value that result in a rehash
68 rehash_values.erase(remove(rehash_values.begin(), rehash_values.end(), i));
69
70 VERIFY( rehash_values == values );
71 }
72
73 int main()
74 {
75 test01();
76 return 0;
77 }