1// { dg-options "-std=gnu++11" }
2
3// Copyright (C) 2013-2015 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 <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{
42  bool test __attribute__((unused)) = true;
43
44  // static_assert(std::__cache_default<int, hash>::value,
45  // 		"Unexpected default cache value");
46  typedef std::unordered_set<int, hash> us_t;
47  us_t us1(10, hash(13));
48  us_t us2(10, hash(7));
49
50  VERIFY( us1.hash_function()._M_modulo == 13 );
51  VERIFY( us2.hash_function()._M_modulo == 7 );
52
53  const int nb = 5;
54  for (int i = 0; i != nb * us1.hash_function()._M_modulo; ++i)
55    us1.insert(i);
56
57  us_t::local_iterator lit = us1.begin(12);
58  us_t::local_iterator litend = us1.end(12);
59  VERIFY( std::distance(lit, litend) == nb );
60
61  us1.swap(us2);
62
63  VERIFY( us1.hash_function()._M_modulo == 7 );
64  VERIFY( us2.hash_function()._M_modulo == 13 );
65
66  VERIFY( std::distance(lit, litend) == nb );
67}
68
69int main()
70{
71  test01();
72}
73