]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/unordered_set/buckets/swap.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / buckets / swap.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
5b3be7cf 2
a945c346 3// Copyright (C) 2013-2024 Free Software Foundation, Inc.
5b3be7cf
FD
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 <testsuite_hooks.h>
21#include <unordered_set>
22
23namespace
24{
25 struct hash
26 {
27 hash() = default;
28 hash(int modulo)
29 : _M_modulo(modulo)
30 { }
31
32 std::size_t operator() (int val) const noexcept
33 { return val % _M_modulo; }
34
35 int _M_modulo;
36 };
37}
38
39void
40test01()
41{
5b3be7cf
FD
42 // static_assert(std::__cache_default<int, hash>::value,
43 // "Unexpected default cache value");
44 typedef std::unordered_set<int, hash> us_t;
45 us_t us1(10, hash(13));
46 us_t us2(10, hash(7));
47
48 VERIFY( us1.hash_function()._M_modulo == 13 );
49 VERIFY( us2.hash_function()._M_modulo == 7 );
50
51 const int nb = 5;
52 for (int i = 0; i != nb * us1.hash_function()._M_modulo; ++i)
53 us1.insert(i);
54
55 us_t::local_iterator lit = us1.begin(12);
56 us_t::local_iterator litend = us1.end(12);
57 VERIFY( std::distance(lit, litend) == nb );
58
59 us1.swap(us2);
60
61 VERIFY( us1.hash_function()._M_modulo == 7 );
62 VERIFY( us2.hash_function()._M_modulo == 13 );
63
64 VERIFY( std::distance(lit, litend) == nb );
65}
66
67int main()
68{
69 test01();
70}