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

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