1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2011-2023 Free Software Foundation, Inc.
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)
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.
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/>.
20 #include <unordered_set>
22 #include <ext/throw_allocator.h>
23 #include <testsuite_hooks.h>
25 template<template<typename _Value
, typename _Hash
,
26 typename _Pred
, typename _Alloc
>
30 typedef std::numeric_limits
<std::size_t> nl_size_t
;
31 _USet
<int, std::hash
<int>, std::equal_to
<int>,
32 __gnu_cxx::throw_allocator_limit
<int> > us
;
34 for (; val
!= 100; ++val
)
36 VERIFY( us
.insert(val
).second
);
37 VERIFY( us
.load_factor() <= us
.max_load_factor() );
40 float cur_max_load_factor
= us
.max_load_factor();
42 std::size_t thrown_exceptions
= 0;
44 // Reduce max load factor.
45 us
.max_load_factor(us
.max_load_factor() / 4);
47 // At this point load factor is higher than max_load_factor because we can't
48 // rehash in max_load_factor call.
49 VERIFY( us
.load_factor() > us
.max_load_factor() );
53 __gnu_cxx::limit_condition::limit_adjustor
adjustor(counter
++);
54 bool do_break
= false;
57 size_t nbkts
= us
.bucket_count();
58 // Check that unordered_set will still be correctly resized when
60 VERIFY( us
.insert(val
++).second
);
61 VERIFY( us
.bucket_count() != nbkts
);
62 VERIFY( us
.load_factor() <= us
.max_load_factor() );
65 catch (const __gnu_cxx::forced_error
&)
67 // max load factor doesn't change.
68 VERIFY( us
.max_load_factor() == .25f
);
76 VERIFY( thrown_exceptions
> 0 );
80 template<typename _Value
, typename _Hash
,
81 typename _Pred
, typename _Alloc
>
82 using unordered_set_power2_rehash
=
83 std::_Hashtable
<_Value
, _Value
, _Alloc
,
84 std::__detail::_Identity
,
87 std::__detail::_Mask_range_hashing
,
88 std::__detail::_Default_ranged_hash
,
89 std::__detail::_Power2_rehash_policy
,
90 std::__detail::_Hashtable_traits
<false, true, true>>;
94 test
<std::unordered_set
>();
95 test
<unordered_set_power2_rehash
>();