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 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03
14 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
15 // class Alloc = allocator<Value>>
16 // class unordered_set
18 // unordered_set& operator=(unordered_set&& u);
20 #include <unordered_set>
26 #include "test_macros.h"
27 #include "../../../test_compare.h"
28 #include "../../../test_hash.h"
29 #include "test_allocator.h"
30 #include "min_allocator.h"
35 typedef test_allocator<int> A;
36 typedef std::unordered_set<int,
37 test_hash<std::hash<int> >,
38 test_compare<std::equal_to<int> >,
51 C c0(a, a + sizeof(a)/sizeof(a[0]),
53 test_hash<std::hash<int> >(8),
54 test_compare<std::equal_to<int> >(9),
59 test_hash<std::hash<int> >(2),
60 test_compare<std::equal_to<int> >(3),
64 LIBCPP_ASSERT(c.bucket_count() == 7);
65 assert(c.size() == 4);
66 assert(c.count(1) == 1);
67 assert(c.count(2) == 1);
68 assert(c.count(3) == 1);
69 assert(c.count(4) == 1);
70 assert(c.hash_function() == test_hash<std::hash<int> >(8));
71 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
72 assert(c.get_allocator() == A(4));
74 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
75 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
76 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
77 assert(c.max_load_factor() == 1);
80 typedef test_allocator<int> A;
81 typedef std::unordered_set<int,
82 test_hash<std::hash<int> >,
83 test_compare<std::equal_to<int> >,
96 C c0(a, a + sizeof(a)/sizeof(a[0]),
98 test_hash<std::hash<int> >(8),
99 test_compare<std::equal_to<int> >(9),
104 test_hash<std::hash<int> >(2),
105 test_compare<std::equal_to<int> >(3),
109 LIBCPP_ASSERT(c.bucket_count() == 7);
110 assert(c.size() == 4);
111 assert(c.count(1) == 1);
112 assert(c.count(2) == 1);
113 assert(c.count(3) == 1);
114 assert(c.count(4) == 1);
115 assert(c.hash_function() == test_hash<std::hash<int> >(8));
116 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
117 assert(c.get_allocator() == A(10));
119 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
120 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
121 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
122 assert(c.max_load_factor() == 1);
125 typedef other_allocator<int> A;
126 typedef std::unordered_set<int,
127 test_hash<std::hash<int> >,
128 test_compare<std::equal_to<int> >,
141 C c0(a, a + sizeof(a)/sizeof(a[0]),
143 test_hash<std::hash<int> >(8),
144 test_compare<std::equal_to<int> >(9),
149 test_hash<std::hash<int> >(2),
150 test_compare<std::equal_to<int> >(3),
154 LIBCPP_ASSERT(c.bucket_count() == 7);
155 assert(c.size() == 4);
156 assert(c.count(1) == 1);
157 assert(c.count(2) == 1);
158 assert(c.count(3) == 1);
159 assert(c.count(4) == 1);
160 assert(c.hash_function() == test_hash<std::hash<int> >(8));
161 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
162 assert(c.get_allocator() == A(10));
164 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
165 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
166 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
167 assert(c.max_load_factor() == 1);
170 typedef min_allocator<int> A;
171 typedef std::unordered_set<int,
172 test_hash<std::hash<int> >,
173 test_compare<std::equal_to<int> >,
186 C c0(a, a + sizeof(a)/sizeof(a[0]),
188 test_hash<std::hash<int> >(8),
189 test_compare<std::equal_to<int> >(9),
194 test_hash<std::hash<int> >(2),
195 test_compare<std::equal_to<int> >(3),
199 LIBCPP_ASSERT(c.bucket_count() == 7);
200 assert(c.size() == 4);
201 assert(c.count(1) == 1);
202 assert(c.count(2) == 1);
203 assert(c.count(3) == 1);
204 assert(c.count(4) == 1);
205 assert(c.hash_function() == test_hash<std::hash<int> >(8));
206 assert(c.key_eq() == test_compare<std::equal_to<int> >(9));
207 assert(c.get_allocator() == A());
209 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
210 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
211 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
212 assert(c.max_load_factor() == 1);