]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_set/hash_policy/71181.cc
Use effective-target instead of -std options
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / unordered_set / hash_policy / 71181.cc
1 // Copyright (C) 2016 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
8 //
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.
13 //
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/>.
17 //
18 // { dg-do run { target c++11 } }
19
20 #include <unordered_set>
21
22 #include <testsuite_hooks.h>
23
24 template<typename _USet>
25 void test(int threshold)
26 {
27 bool test __attribute__((unused)) = true;
28 _USet us;
29 auto nb_reserved = us.bucket_count();
30 us.reserve(nb_reserved);
31 auto bkts = us.bucket_count();
32 for (int i = 0; i != threshold; ++i)
33 {
34 if (i == nb_reserved)
35 {
36 nb_reserved = bkts;
37 us.reserve(nb_reserved);
38 bkts = us.bucket_count();
39 }
40
41 us.insert(i);
42
43 VERIFY( us.bucket_count() == bkts );
44 }
45 }
46
47 template<typename _Value>
48 using unordered_set_power2_rehash =
49 std::_Hashtable<_Value, _Value, std::allocator<_Value>,
50 std::__detail::_Identity,
51 std::equal_to<_Value>,
52 std::hash<_Value>,
53 std::__detail::_Mask_range_hashing,
54 std::__detail::_Default_ranged_hash,
55 std::__detail::_Power2_rehash_policy,
56 std::__detail::_Hashtable_traits<false, true, true>>;
57
58 int main()
59 {
60 test<std::unordered_set<int>>(150);
61 test<unordered_set_power2_rehash<int>>(150);
62 return 0;
63 }