1 | //===----------------------------------------------------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <unordered_set> |
10 | |
11 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
12 | // class Alloc = allocator<Value>> |
13 | // class unordered_set |
14 | |
15 | // void swap(unordered_set& x, unordered_set& y); |
16 | |
17 | #include <unordered_set> |
18 | #include <cassert> |
19 | #include <cstddef> |
20 | |
21 | #include "test_macros.h" |
22 | #include "../../../test_compare.h" |
23 | #include "../../../test_hash.h" |
24 | #include "test_allocator.h" |
25 | #include "min_allocator.h" |
26 | |
27 | int main(int, char**) |
28 | { |
29 | { |
30 | typedef test_hash<int> Hash; |
31 | typedef test_equal_to<int> Compare; |
32 | typedef test_allocator<int> Alloc; |
33 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
34 | C c1(0, Hash(1), Compare(1), Alloc(1, 1)); |
35 | C c2(0, Hash(2), Compare(2), Alloc(1, 2)); |
36 | c2.max_load_factor(z: 2); |
37 | swap(c1, c2); |
38 | |
39 | LIBCPP_ASSERT(c1.bucket_count() == 0); |
40 | assert(c1.size() == 0); |
41 | assert(c1.hash_function() == Hash(2)); |
42 | assert(c1.key_eq() == Compare(2)); |
43 | assert(c1.get_allocator().get_id() == 1); |
44 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
45 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
46 | assert(c1.max_load_factor() == 2); |
47 | |
48 | LIBCPP_ASSERT(c2.bucket_count() == 0); |
49 | assert(c2.size() == 0); |
50 | assert(c2.hash_function() == Hash(1)); |
51 | assert(c2.key_eq() == Compare(1)); |
52 | assert(c2.get_allocator().get_id() == 2); |
53 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
54 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
55 | assert(c2.max_load_factor() == 1); |
56 | } |
57 | { |
58 | typedef test_hash<int> Hash; |
59 | typedef test_equal_to<int> Compare; |
60 | typedef test_allocator<int> Alloc; |
61 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
62 | typedef int P; |
63 | P a2[] = |
64 | { |
65 | P(10), |
66 | P(20), |
67 | P(30), |
68 | P(40), |
69 | P(50), |
70 | P(60), |
71 | P(70), |
72 | P(80) |
73 | }; |
74 | C c1(0, Hash(1), Compare(1), Alloc(1, 1)); |
75 | C c2(std::begin(arr&: a2), std::end(arr&: a2), 0, Hash(2), Compare(2), Alloc(1, 2)); |
76 | c2.max_load_factor(z: 2); |
77 | C::iterator it2 = c2.begin(); |
78 | swap(x&: c1, y&: c2); |
79 | |
80 | assert(c1.bucket_count() >= 8); |
81 | assert(c1.size() == 8); |
82 | assert(*c1.find(10) == 10); |
83 | assert(*c1.find(20) == 20); |
84 | assert(*c1.find(30) == 30); |
85 | assert(*c1.find(40) == 40); |
86 | assert(*c1.find(50) == 50); |
87 | assert(*c1.find(60) == 60); |
88 | assert(*c1.find(70) == 70); |
89 | assert(*c1.find(80) == 80); |
90 | assert(c1.hash_function() == Hash(2)); |
91 | assert(c1.key_eq() == Compare(2)); |
92 | assert(c1.get_allocator().get_id() == 1); |
93 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
94 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
95 | assert(c1.max_load_factor() == 2); |
96 | assert(it2 == c1.begin()); // Iterators are not invalidated |
97 | |
98 | LIBCPP_ASSERT(c2.bucket_count() == 0); |
99 | assert(c2.size() == 0); |
100 | assert(c2.hash_function() == Hash(1)); |
101 | assert(c2.key_eq() == Compare(1)); |
102 | assert(c2.get_allocator().get_id() == 2); |
103 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
104 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
105 | assert(c2.max_load_factor() == 1); |
106 | } |
107 | { |
108 | typedef test_hash<int> Hash; |
109 | typedef test_equal_to<int> Compare; |
110 | typedef test_allocator<int> Alloc; |
111 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
112 | typedef int P; |
113 | P a1[] = |
114 | { |
115 | P(1), |
116 | P(2), |
117 | P(3), |
118 | P(4), |
119 | P(1), |
120 | P(2) |
121 | }; |
122 | C c1(std::begin(arr&: a1), std::end(arr&: a1), 0, Hash(1), Compare(1), Alloc(1, 1)); |
123 | C c2(0, Hash(2), Compare(2), Alloc(1, 2)); |
124 | c2.max_load_factor(z: 2); |
125 | C::iterator it1 = c1.begin(); |
126 | swap(x&: c1, y&: c2); |
127 | |
128 | LIBCPP_ASSERT(c1.bucket_count() == 0); |
129 | assert(c1.size() == 0); |
130 | assert(c1.hash_function() == Hash(2)); |
131 | assert(c1.key_eq() == Compare(2)); |
132 | assert(c1.get_allocator().get_id() == 1); |
133 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
134 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
135 | assert(c1.max_load_factor() == 2); |
136 | |
137 | assert(c2.bucket_count() >= 4); |
138 | assert(c2.size() == 4); |
139 | assert(c2.count(1) == 1); |
140 | assert(c2.count(2) == 1); |
141 | assert(c2.count(3) == 1); |
142 | assert(c2.count(4) == 1); |
143 | assert(c2.hash_function() == Hash(1)); |
144 | assert(c2.key_eq() == Compare(1)); |
145 | assert(c2.get_allocator().get_id() == 2); |
146 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
147 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
148 | assert(c2.max_load_factor() == 1); |
149 | assert(it1 == c2.begin()); // Iterators are not invalidated |
150 | } |
151 | { |
152 | typedef test_hash<int> Hash; |
153 | typedef test_equal_to<int> Compare; |
154 | typedef test_allocator<int> Alloc; |
155 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
156 | typedef int P; |
157 | P a1[] = |
158 | { |
159 | P(1), |
160 | P(2), |
161 | P(3), |
162 | P(4), |
163 | P(1), |
164 | P(2) |
165 | }; |
166 | P a2[] = |
167 | { |
168 | P(10), |
169 | P(20), |
170 | P(30), |
171 | P(40), |
172 | P(50), |
173 | P(60), |
174 | P(70), |
175 | P(80) |
176 | }; |
177 | C c1(std::begin(arr&: a1), std::end(arr&: a1), 0, Hash(1), Compare(1), Alloc(1, 1)); |
178 | C c2(std::begin(arr&: a2), std::end(arr&: a2), 0, Hash(2), Compare(2), Alloc(1, 2)); |
179 | c2.max_load_factor(z: 2); |
180 | C::iterator it1 = c1.begin(); |
181 | C::iterator it2 = c2.begin(); |
182 | swap(x&: c1, y&: c2); |
183 | |
184 | assert(c1.bucket_count() >= 8); |
185 | assert(c1.size() == 8); |
186 | assert(*c1.find(10) == 10); |
187 | assert(*c1.find(20) == 20); |
188 | assert(*c1.find(30) == 30); |
189 | assert(*c1.find(40) == 40); |
190 | assert(*c1.find(50) == 50); |
191 | assert(*c1.find(60) == 60); |
192 | assert(*c1.find(70) == 70); |
193 | assert(*c1.find(80) == 80); |
194 | assert(c1.hash_function() == Hash(2)); |
195 | assert(c1.key_eq() == Compare(2)); |
196 | assert(c1.get_allocator().get_id() == 1); |
197 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
198 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
199 | assert(c1.max_load_factor() == 2); |
200 | assert(it2 == c1.begin()); // Iterators are not invalidated |
201 | |
202 | assert(c2.bucket_count() >= 4); |
203 | assert(c2.size() == 4); |
204 | assert(c2.count(1) == 1); |
205 | assert(c2.count(2) == 1); |
206 | assert(c2.count(3) == 1); |
207 | assert(c2.count(4) == 1); |
208 | assert(c2.hash_function() == Hash(1)); |
209 | assert(c2.key_eq() == Compare(1)); |
210 | assert(c2.get_allocator().get_id() == 2); |
211 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
212 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
213 | assert(c2.max_load_factor() == 1); |
214 | assert(it1 == c2.begin()); // Iterators are not invalidated |
215 | } |
216 | |
217 | { |
218 | typedef test_hash<int> Hash; |
219 | typedef test_equal_to<int> Compare; |
220 | typedef other_allocator<int> Alloc; |
221 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
222 | C c1(0, Hash(1), Compare(1), Alloc(1)); |
223 | C c2(0, Hash(2), Compare(2), Alloc(2)); |
224 | c2.max_load_factor(z: 2); |
225 | swap(x&: c1, y&: c2); |
226 | |
227 | LIBCPP_ASSERT(c1.bucket_count() == 0); |
228 | assert(c1.size() == 0); |
229 | assert(c1.hash_function() == Hash(2)); |
230 | assert(c1.key_eq() == Compare(2)); |
231 | assert(c1.get_allocator() == Alloc(2)); |
232 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
233 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
234 | assert(c1.max_load_factor() == 2); |
235 | |
236 | LIBCPP_ASSERT(c2.bucket_count() == 0); |
237 | assert(c2.size() == 0); |
238 | assert(c2.hash_function() == Hash(1)); |
239 | assert(c2.key_eq() == Compare(1)); |
240 | assert(c2.get_allocator() == Alloc(1)); |
241 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
242 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
243 | assert(c2.max_load_factor() == 1); |
244 | } |
245 | { |
246 | typedef test_hash<int> Hash; |
247 | typedef test_equal_to<int> Compare; |
248 | typedef other_allocator<int> Alloc; |
249 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
250 | typedef int P; |
251 | P a2[] = |
252 | { |
253 | P(10), |
254 | P(20), |
255 | P(30), |
256 | P(40), |
257 | P(50), |
258 | P(60), |
259 | P(70), |
260 | P(80) |
261 | }; |
262 | C c1(0, Hash(1), Compare(1), Alloc(1)); |
263 | C c2(std::begin(arr&: a2), std::end(arr&: a2), 0, Hash(2), Compare(2), Alloc(2)); |
264 | c2.max_load_factor(z: 2); |
265 | swap(x&: c1, y&: c2); |
266 | |
267 | assert(c1.bucket_count() >= 8); |
268 | assert(c1.size() == 8); |
269 | assert(*c1.find(10) == 10); |
270 | assert(*c1.find(20) == 20); |
271 | assert(*c1.find(30) == 30); |
272 | assert(*c1.find(40) == 40); |
273 | assert(*c1.find(50) == 50); |
274 | assert(*c1.find(60) == 60); |
275 | assert(*c1.find(70) == 70); |
276 | assert(*c1.find(80) == 80); |
277 | assert(c1.hash_function() == Hash(2)); |
278 | assert(c1.key_eq() == Compare(2)); |
279 | assert(c1.get_allocator() == Alloc(2)); |
280 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
281 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
282 | assert(c1.max_load_factor() == 2); |
283 | |
284 | LIBCPP_ASSERT(c2.bucket_count() == 0); |
285 | assert(c2.size() == 0); |
286 | assert(c2.hash_function() == Hash(1)); |
287 | assert(c2.key_eq() == Compare(1)); |
288 | assert(c2.get_allocator() == Alloc(1)); |
289 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
290 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
291 | assert(c2.max_load_factor() == 1); |
292 | } |
293 | { |
294 | typedef test_hash<int> Hash; |
295 | typedef test_equal_to<int> Compare; |
296 | typedef other_allocator<int> Alloc; |
297 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
298 | typedef int P; |
299 | P a1[] = |
300 | { |
301 | P(1), |
302 | P(2), |
303 | P(3), |
304 | P(4), |
305 | P(1), |
306 | P(2) |
307 | }; |
308 | C c1(std::begin(arr&: a1), std::end(arr&: a1), 0, Hash(1), Compare(1), Alloc(1)); |
309 | C c2(0, Hash(2), Compare(2), Alloc(2)); |
310 | c2.max_load_factor(z: 2); |
311 | swap(x&: c1, y&: c2); |
312 | |
313 | LIBCPP_ASSERT(c1.bucket_count() == 0); |
314 | assert(c1.size() == 0); |
315 | assert(c1.hash_function() == Hash(2)); |
316 | assert(c1.key_eq() == Compare(2)); |
317 | assert(c1.get_allocator() == Alloc(2)); |
318 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
319 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
320 | assert(c1.max_load_factor() == 2); |
321 | |
322 | assert(c2.bucket_count() >= 4); |
323 | assert(c2.size() == 4); |
324 | assert(c2.count(1) == 1); |
325 | assert(c2.count(2) == 1); |
326 | assert(c2.count(3) == 1); |
327 | assert(c2.count(4) == 1); |
328 | assert(c2.hash_function() == Hash(1)); |
329 | assert(c2.key_eq() == Compare(1)); |
330 | assert(c2.get_allocator() == Alloc(1)); |
331 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
332 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
333 | assert(c2.max_load_factor() == 1); |
334 | } |
335 | { |
336 | typedef test_hash<int> Hash; |
337 | typedef test_equal_to<int> Compare; |
338 | typedef other_allocator<int> Alloc; |
339 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
340 | typedef int P; |
341 | P a1[] = |
342 | { |
343 | P(1), |
344 | P(2), |
345 | P(3), |
346 | P(4), |
347 | P(1), |
348 | P(2) |
349 | }; |
350 | P a2[] = |
351 | { |
352 | P(10), |
353 | P(20), |
354 | P(30), |
355 | P(40), |
356 | P(50), |
357 | P(60), |
358 | P(70), |
359 | P(80) |
360 | }; |
361 | C c1(std::begin(arr&: a1), std::end(arr&: a1), 0, Hash(1), Compare(1), Alloc(1)); |
362 | C c2(std::begin(arr&: a2), std::end(arr&: a2), 0, Hash(2), Compare(2), Alloc(2)); |
363 | c2.max_load_factor(z: 2); |
364 | swap(x&: c1, y&: c2); |
365 | |
366 | assert(c1.bucket_count() >= 8); |
367 | assert(c1.size() == 8); |
368 | assert(*c1.find(10) == 10); |
369 | assert(*c1.find(20) == 20); |
370 | assert(*c1.find(30) == 30); |
371 | assert(*c1.find(40) == 40); |
372 | assert(*c1.find(50) == 50); |
373 | assert(*c1.find(60) == 60); |
374 | assert(*c1.find(70) == 70); |
375 | assert(*c1.find(80) == 80); |
376 | assert(c1.hash_function() == Hash(2)); |
377 | assert(c1.key_eq() == Compare(2)); |
378 | assert(c1.get_allocator() == Alloc(2)); |
379 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
380 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
381 | assert(c1.max_load_factor() == 2); |
382 | |
383 | assert(c2.bucket_count() >= 4); |
384 | assert(c2.size() == 4); |
385 | assert(c2.count(1) == 1); |
386 | assert(c2.count(2) == 1); |
387 | assert(c2.count(3) == 1); |
388 | assert(c2.count(4) == 1); |
389 | assert(c2.hash_function() == Hash(1)); |
390 | assert(c2.key_eq() == Compare(1)); |
391 | assert(c2.get_allocator() == Alloc(1)); |
392 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
393 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
394 | assert(c2.max_load_factor() == 1); |
395 | } |
396 | #if TEST_STD_VER >= 11 |
397 | { |
398 | typedef test_hash<int> Hash; |
399 | typedef test_equal_to<int> Compare; |
400 | typedef min_allocator<int> Alloc; |
401 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
402 | C c1(0, Hash(1), Compare(1), Alloc()); |
403 | C c2(0, Hash(2), Compare(2), Alloc()); |
404 | c2.max_load_factor(2); |
405 | swap(c1, c2); |
406 | |
407 | LIBCPP_ASSERT(c1.bucket_count() == 0); |
408 | assert(c1.size() == 0); |
409 | assert(c1.hash_function() == Hash(2)); |
410 | assert(c1.key_eq() == Compare(2)); |
411 | assert(c1.get_allocator() == Alloc()); |
412 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
413 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
414 | assert(c1.max_load_factor() == 2); |
415 | |
416 | LIBCPP_ASSERT(c2.bucket_count() == 0); |
417 | assert(c2.size() == 0); |
418 | assert(c2.hash_function() == Hash(1)); |
419 | assert(c2.key_eq() == Compare(1)); |
420 | assert(c2.get_allocator() == Alloc()); |
421 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
422 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
423 | assert(c2.max_load_factor() == 1); |
424 | } |
425 | { |
426 | typedef test_hash<int> Hash; |
427 | typedef test_equal_to<int> Compare; |
428 | typedef min_allocator<int> Alloc; |
429 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
430 | typedef int P; |
431 | P a2[] = |
432 | { |
433 | P(10), |
434 | P(20), |
435 | P(30), |
436 | P(40), |
437 | P(50), |
438 | P(60), |
439 | P(70), |
440 | P(80) |
441 | }; |
442 | C c1(0, Hash(1), Compare(1), Alloc()); |
443 | C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); |
444 | c2.max_load_factor(2); |
445 | swap(c1, c2); |
446 | |
447 | assert(c1.bucket_count() >= 8); |
448 | assert(c1.size() == 8); |
449 | assert(*c1.find(10) == 10); |
450 | assert(*c1.find(20) == 20); |
451 | assert(*c1.find(30) == 30); |
452 | assert(*c1.find(40) == 40); |
453 | assert(*c1.find(50) == 50); |
454 | assert(*c1.find(60) == 60); |
455 | assert(*c1.find(70) == 70); |
456 | assert(*c1.find(80) == 80); |
457 | assert(c1.hash_function() == Hash(2)); |
458 | assert(c1.key_eq() == Compare(2)); |
459 | assert(c1.get_allocator() == Alloc()); |
460 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
461 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
462 | assert(c1.max_load_factor() == 2); |
463 | |
464 | LIBCPP_ASSERT(c2.bucket_count() == 0); |
465 | assert(c2.size() == 0); |
466 | assert(c2.hash_function() == Hash(1)); |
467 | assert(c2.key_eq() == Compare(1)); |
468 | assert(c2.get_allocator() == Alloc()); |
469 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
470 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
471 | assert(c2.max_load_factor() == 1); |
472 | } |
473 | { |
474 | typedef test_hash<int> Hash; |
475 | typedef test_equal_to<int> Compare; |
476 | typedef min_allocator<int> Alloc; |
477 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
478 | typedef int P; |
479 | P a1[] = |
480 | { |
481 | P(1), |
482 | P(2), |
483 | P(3), |
484 | P(4), |
485 | P(1), |
486 | P(2) |
487 | }; |
488 | C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); |
489 | C c2(0, Hash(2), Compare(2), Alloc()); |
490 | c2.max_load_factor(2); |
491 | swap(c1, c2); |
492 | |
493 | LIBCPP_ASSERT(c1.bucket_count() == 0); |
494 | assert(c1.size() == 0); |
495 | assert(c1.hash_function() == Hash(2)); |
496 | assert(c1.key_eq() == Compare(2)); |
497 | assert(c1.get_allocator() == Alloc()); |
498 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
499 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
500 | assert(c1.max_load_factor() == 2); |
501 | |
502 | assert(c2.bucket_count() >= 4); |
503 | assert(c2.size() == 4); |
504 | assert(c2.count(1) == 1); |
505 | assert(c2.count(2) == 1); |
506 | assert(c2.count(3) == 1); |
507 | assert(c2.count(4) == 1); |
508 | assert(c2.hash_function() == Hash(1)); |
509 | assert(c2.key_eq() == Compare(1)); |
510 | assert(c2.get_allocator() == Alloc()); |
511 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
512 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
513 | assert(c2.max_load_factor() == 1); |
514 | } |
515 | { |
516 | typedef test_hash<int> Hash; |
517 | typedef test_equal_to<int> Compare; |
518 | typedef min_allocator<int> Alloc; |
519 | typedef std::unordered_set<int, Hash, Compare, Alloc> C; |
520 | typedef int P; |
521 | P a1[] = |
522 | { |
523 | P(1), |
524 | P(2), |
525 | P(3), |
526 | P(4), |
527 | P(1), |
528 | P(2) |
529 | }; |
530 | P a2[] = |
531 | { |
532 | P(10), |
533 | P(20), |
534 | P(30), |
535 | P(40), |
536 | P(50), |
537 | P(60), |
538 | P(70), |
539 | P(80) |
540 | }; |
541 | C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); |
542 | C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); |
543 | c2.max_load_factor(2); |
544 | swap(c1, c2); |
545 | |
546 | assert(c1.bucket_count() >= 8); |
547 | assert(c1.size() == 8); |
548 | assert(*c1.find(10) == 10); |
549 | assert(*c1.find(20) == 20); |
550 | assert(*c1.find(30) == 30); |
551 | assert(*c1.find(40) == 40); |
552 | assert(*c1.find(50) == 50); |
553 | assert(*c1.find(60) == 60); |
554 | assert(*c1.find(70) == 70); |
555 | assert(*c1.find(80) == 80); |
556 | assert(c1.hash_function() == Hash(2)); |
557 | assert(c1.key_eq() == Compare(2)); |
558 | assert(c1.get_allocator() == Alloc()); |
559 | assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size()); |
560 | assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size()); |
561 | assert(c1.max_load_factor() == 2); |
562 | |
563 | assert(c2.bucket_count() >= 4); |
564 | assert(c2.size() == 4); |
565 | assert(c2.count(1) == 1); |
566 | assert(c2.count(2) == 1); |
567 | assert(c2.count(3) == 1); |
568 | assert(c2.count(4) == 1); |
569 | assert(c2.hash_function() == Hash(1)); |
570 | assert(c2.key_eq() == Compare(1)); |
571 | assert(c2.get_allocator() == Alloc()); |
572 | assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size()); |
573 | assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size()); |
574 | assert(c2.max_load_factor() == 1); |
575 | } |
576 | #endif |
577 | |
578 | return 0; |
579 | } |
580 | |