1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
13 // class Alloc = allocator<Value>>
14 // class unordered_set
16 // void rehash(size_type n);
18 #include <unordered_set>
21 #include "test_macros.h"
22 #include "min_allocator.h"
25 void rehash_postcondition(const C& c, size_t n)
27 assert(c.bucket_count() >= c.size() / c.max_load_factor() && c.bucket_count() >= n);
33 assert(c.size() == 4);
34 assert(c.count(1) == 1);
35 assert(c.count(2) == 1);
36 assert(c.count(3) == 1);
37 assert(c.count(4) == 1);
43 typedef std::unordered_set<int> C;
54 C c(a, a + sizeof(a)/sizeof(a[0]));
56 assert(c.bucket_count() >= 5);
58 rehash_postcondition(c, 3);
59 LIBCPP_ASSERT(c.bucket_count() == 5);
63 rehash_postcondition(c, 3);
64 LIBCPP_ASSERT(c.bucket_count() == 3);
67 rehash_postcondition(c, 31);
68 LIBCPP_ASSERT(c.bucket_count() == 31);
71 #if TEST_STD_VER >= 11
73 typedef std::unordered_set<int, std::hash<int>,
74 std::equal_to<int>, min_allocator<int>> C;
85 C c(a, a + sizeof(a)/sizeof(a[0]));
87 assert(c.bucket_count() >= 5);
89 rehash_postcondition(c, 3);
90 LIBCPP_ASSERT(c.bucket_count() == 5);
94 rehash_postcondition(c, 3);
95 LIBCPP_ASSERT(c.bucket_count() == 3);
98 rehash_postcondition(c, 31);
99 LIBCPP_ASSERT(c.bucket_count() == 31);