]> 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-do run { target c++11 } }
2 //
3 // Copyright (C) 2012-2023 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
47 unordered_multiset<pair<int, int>, pair_hash, pair_equal_to> mset;
48 vector<int> values;
49
50 size_t nb_bkts = mset.bucket_count();
51 int i = 0;
52 for (;; ++i)
53 {
54 mset.insert(make_pair(0, i));
55 if (mset.bucket_count() != nb_bkts)
56 // Container got rehash
57 break;
58 values.clear();
59 transform(mset.begin(), mset.end(), back_inserter(values),
60 [](const pair<int, int>& p) { return p.second; });
61 }
62
63 vector<int> rehash_values;
64 transform(mset.begin(), mset.end(), back_inserter(rehash_values),
65 [](const pair<int, int>& p) { return p.second; });
66 // Remove the value that result in a rehash
67 rehash_values.erase(remove(rehash_values.begin(), rehash_values.end(), i));
68
69 VERIFY( rehash_values == values );
70 }
71
72 int main()
73 {
74 test01();
75 return 0;
76 }