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

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