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

source code of libcxx/test/std/containers/unord/unord.map/swap_member.pass.cpp