xref: /llvm-project/libcxx/test/std/containers/unord/unord.multimap/swap_member.pass.cpp (revision 3cd4531b9ba421d1d096e746d787fe3039a546bb)
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 "../../test_compare.h"
26 #include "../../test_hash.h"
27 #include "test_allocator.h"
28 
29 #include "min_allocator.h"
30 
main(int,char **)31 int 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(2);
41         c1.swap(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(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
80         c2.max_load_factor(2);
81         c1.swap(c2);
82 
83         assert(c1.bucket_count() >= 8);
84         assert(c1.size() == 8);
85         assert(c1.find(10)->second == "ten");
86         assert(c1.find(20)->second == "twenty");
87         assert(c1.find(30)->second == "thirty");
88         assert(c1.find(40)->second == "forty");
89         assert(c1.find(50)->second == "fifty");
90         assert(c1.find(60)->second == "sixty");
91         assert(c1.find(70)->second == "seventy");
92         assert(c1.find(80)->second == "eighty");
93         assert(c1.hash_function() == Hash(2));
94         assert(c1.key_eq() == Compare(2));
95         assert(c1.get_allocator().get_id() == 1);
96         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
97         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
98         assert(c1.max_load_factor() == 2);
99 
100         LIBCPP_ASSERT(c2.bucket_count() == 0);
101         assert(c2.size() == 0);
102         assert(c2.hash_function() == Hash(1));
103         assert(c2.key_eq() == Compare(1));
104         assert(c2.get_allocator().get_id() == 2);
105         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
106         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
107         assert(c2.max_load_factor() == 1);
108     }
109     {
110         typedef test_hash<int> Hash;
111         typedef test_equal_to<int> Compare;
112         typedef test_allocator<std::pair<const int, std::string> > Alloc;
113         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
114         typedef std::pair<int, std::string> P;
115         P a1[] =
116         {
117             P(1, "one"),
118             P(2, "two"),
119             P(3, "three"),
120             P(4, "four"),
121             P(1, "four"),
122             P(2, "four"),
123         };
124         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
125         C c2(0, Hash(2), Compare(2), Alloc(1, 2));
126         c2.max_load_factor(2);
127         c1.swap(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() >= 6);
139         assert(c2.size() == 6);
140         {
141             std::set<std::string> s;
142             s.insert("one");
143             s.insert("four");
144             assert(s.find(c2.find(1)->second) != s.end());
145             s.erase(s.find(c2.find(1)->second));
146             assert(s.find(std::next(c2.find(1))->second) != s.end());
147         }
148         {
149             std::set<std::string> s;
150             s.insert("two");
151             s.insert("four");
152             assert(s.find(c2.find(2)->second) != s.end());
153             s.erase(s.find(c2.find(2)->second));
154             assert(s.find(std::next(c2.find(2))->second) != s.end());
155         }
156         assert(c2.find(3)->second == "three");
157         assert(c2.find(4)->second == "four");
158         assert(c2.hash_function() == Hash(1));
159         assert(c2.key_eq() == Compare(1));
160         assert(c2.get_allocator().get_id() == 2);
161         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
162         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
163         assert(c2.max_load_factor() == 1);
164     }
165     {
166         typedef test_hash<int> Hash;
167         typedef test_equal_to<int> Compare;
168         typedef test_allocator<std::pair<const int, std::string> > Alloc;
169         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
170         typedef std::pair<int, std::string> P;
171         P a1[] =
172         {
173             P(1, "one"),
174             P(2, "two"),
175             P(3, "three"),
176             P(4, "four"),
177             P(1, "four"),
178             P(2, "four"),
179         };
180         P a2[] =
181         {
182             P(10, "ten"),
183             P(20, "twenty"),
184             P(30, "thirty"),
185             P(40, "forty"),
186             P(50, "fifty"),
187             P(60, "sixty"),
188             P(70, "seventy"),
189             P(80, "eighty"),
190         };
191         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1, 1));
192         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(1, 2));
193         c2.max_load_factor(2);
194         c1.swap(c2);
195 
196         assert(c1.bucket_count() >= 8);
197         assert(c1.size() == 8);
198         assert(c1.find(10)->second == "ten");
199         assert(c1.find(20)->second == "twenty");
200         assert(c1.find(30)->second == "thirty");
201         assert(c1.find(40)->second == "forty");
202         assert(c1.find(50)->second == "fifty");
203         assert(c1.find(60)->second == "sixty");
204         assert(c1.find(70)->second == "seventy");
205         assert(c1.find(80)->second == "eighty");
206         assert(c1.hash_function() == Hash(2));
207         assert(c1.key_eq() == Compare(2));
208         assert(c1.get_allocator().get_id() == 1);
209         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
210         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
211         assert(c1.max_load_factor() == 2);
212 
213         assert(c2.bucket_count() >= 6);
214         assert(c2.size() == 6);
215         {
216             std::set<std::string> s;
217             s.insert("one");
218             s.insert("four");
219             assert(s.find(c2.find(1)->second) != s.end());
220             s.erase(s.find(c2.find(1)->second));
221             assert(s.find(std::next(c2.find(1))->second) != s.end());
222         }
223         {
224             std::set<std::string> s;
225             s.insert("two");
226             s.insert("four");
227             assert(s.find(c2.find(2)->second) != s.end());
228             s.erase(s.find(c2.find(2)->second));
229             assert(s.find(std::next(c2.find(2))->second) != s.end());
230         }
231         assert(c2.find(3)->second == "three");
232         assert(c2.find(4)->second == "four");
233         assert(c2.hash_function() == Hash(1));
234         assert(c2.key_eq() == Compare(1));
235         assert(c2.get_allocator().get_id() == 2);
236         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
237         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
238         assert(c2.max_load_factor() == 1);
239     }
240 
241     {
242         typedef test_hash<int> Hash;
243         typedef test_equal_to<int> Compare;
244         typedef other_allocator<std::pair<const int, std::string> > Alloc;
245         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
246         C c1(0, Hash(1), Compare(1), Alloc(1));
247         C c2(0, Hash(2), Compare(2), Alloc(2));
248         c2.max_load_factor(2);
249         c1.swap(c2);
250 
251         LIBCPP_ASSERT(c1.bucket_count() == 0);
252         assert(c1.size() == 0);
253         assert(c1.hash_function() == Hash(2));
254         assert(c1.key_eq() == Compare(2));
255         assert(c1.get_allocator() == Alloc(2));
256         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
257         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
258         assert(c1.max_load_factor() == 2);
259 
260         LIBCPP_ASSERT(c2.bucket_count() == 0);
261         assert(c2.size() == 0);
262         assert(c2.hash_function() == Hash(1));
263         assert(c2.key_eq() == Compare(1));
264         assert(c2.get_allocator() == Alloc(1));
265         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
266         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
267         assert(c2.max_load_factor() == 1);
268     }
269     {
270         typedef test_hash<int> Hash;
271         typedef test_equal_to<int> Compare;
272         typedef other_allocator<std::pair<const int, std::string> > Alloc;
273         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
274         typedef std::pair<int, std::string> P;
275         P a2[] =
276         {
277             P(10, "ten"),
278             P(20, "twenty"),
279             P(30, "thirty"),
280             P(40, "forty"),
281             P(50, "fifty"),
282             P(60, "sixty"),
283             P(70, "seventy"),
284             P(80, "eighty"),
285         };
286         C c1(0, Hash(1), Compare(1), Alloc(1));
287         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2));
288         c2.max_load_factor(2);
289         c1.swap(c2);
290 
291         assert(c1.bucket_count() >= 8);
292         assert(c1.size() == 8);
293         assert(c1.find(10)->second == "ten");
294         assert(c1.find(20)->second == "twenty");
295         assert(c1.find(30)->second == "thirty");
296         assert(c1.find(40)->second == "forty");
297         assert(c1.find(50)->second == "fifty");
298         assert(c1.find(60)->second == "sixty");
299         assert(c1.find(70)->second == "seventy");
300         assert(c1.find(80)->second == "eighty");
301         assert(c1.hash_function() == Hash(2));
302         assert(c1.key_eq() == Compare(2));
303         assert(c1.get_allocator() == Alloc(2));
304         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
305         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
306         assert(c1.max_load_factor() == 2);
307 
308         LIBCPP_ASSERT(c2.bucket_count() == 0);
309         assert(c2.size() == 0);
310         assert(c2.hash_function() == Hash(1));
311         assert(c2.key_eq() == Compare(1));
312         assert(c2.get_allocator() == Alloc(1));
313         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
314         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
315         assert(c2.max_load_factor() == 1);
316     }
317     {
318         typedef test_hash<int> Hash;
319         typedef test_equal_to<int> Compare;
320         typedef other_allocator<std::pair<const int, std::string> > Alloc;
321         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
322         typedef std::pair<int, std::string> P;
323         P a1[] =
324         {
325             P(1, "one"),
326             P(2, "two"),
327             P(3, "three"),
328             P(4, "four"),
329             P(1, "four"),
330             P(2, "four"),
331         };
332         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1));
333         C c2(0, Hash(2), Compare(2), Alloc(2));
334         c2.max_load_factor(2);
335         c1.swap(c2);
336 
337         LIBCPP_ASSERT(c1.bucket_count() == 0);
338         assert(c1.size() == 0);
339         assert(c1.hash_function() == Hash(2));
340         assert(c1.key_eq() == Compare(2));
341         assert(c1.get_allocator() == Alloc(2));
342         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
343         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
344         assert(c1.max_load_factor() == 2);
345 
346         assert(c2.bucket_count() >= 6);
347         assert(c2.size() == 6);
348         {
349             std::set<std::string> s;
350             s.insert("one");
351             s.insert("four");
352             assert(s.find(c2.find(1)->second) != s.end());
353             s.erase(s.find(c2.find(1)->second));
354             assert(s.find(std::next(c2.find(1))->second) != s.end());
355         }
356         {
357             std::set<std::string> s;
358             s.insert("two");
359             s.insert("four");
360             assert(s.find(c2.find(2)->second) != s.end());
361             s.erase(s.find(c2.find(2)->second));
362             assert(s.find(std::next(c2.find(2))->second) != s.end());
363         }
364         assert(c2.find(3)->second == "three");
365         assert(c2.find(4)->second == "four");
366         assert(c2.hash_function() == Hash(1));
367         assert(c2.key_eq() == Compare(1));
368         assert(c2.get_allocator() == Alloc(1));
369         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
370         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
371         assert(c2.max_load_factor() == 1);
372     }
373     {
374         typedef test_hash<int> Hash;
375         typedef test_equal_to<int> Compare;
376         typedef other_allocator<std::pair<const int, std::string> > Alloc;
377         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
378         typedef std::pair<int, std::string> P;
379         P a1[] =
380         {
381             P(1, "one"),
382             P(2, "two"),
383             P(3, "three"),
384             P(4, "four"),
385             P(1, "four"),
386             P(2, "four"),
387         };
388         P a2[] =
389         {
390             P(10, "ten"),
391             P(20, "twenty"),
392             P(30, "thirty"),
393             P(40, "forty"),
394             P(50, "fifty"),
395             P(60, "sixty"),
396             P(70, "seventy"),
397             P(80, "eighty"),
398         };
399         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1));
400         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2));
401         c2.max_load_factor(2);
402         c1.swap(c2);
403 
404         assert(c1.bucket_count() >= 8);
405         assert(c1.size() == 8);
406         assert(c1.find(10)->second == "ten");
407         assert(c1.find(20)->second == "twenty");
408         assert(c1.find(30)->second == "thirty");
409         assert(c1.find(40)->second == "forty");
410         assert(c1.find(50)->second == "fifty");
411         assert(c1.find(60)->second == "sixty");
412         assert(c1.find(70)->second == "seventy");
413         assert(c1.find(80)->second == "eighty");
414         assert(c1.hash_function() == Hash(2));
415         assert(c1.key_eq() == Compare(2));
416         assert(c1.get_allocator() == Alloc(2));
417         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
418         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
419         assert(c1.max_load_factor() == 2);
420 
421         assert(c2.bucket_count() >= 6);
422         assert(c2.size() == 6);
423         {
424             std::set<std::string> s;
425             s.insert("one");
426             s.insert("four");
427             assert(s.find(c2.find(1)->second) != s.end());
428             s.erase(s.find(c2.find(1)->second));
429             assert(s.find(std::next(c2.find(1))->second) != s.end());
430         }
431         {
432             std::set<std::string> s;
433             s.insert("two");
434             s.insert("four");
435             assert(s.find(c2.find(2)->second) != s.end());
436             s.erase(s.find(c2.find(2)->second));
437             assert(s.find(std::next(c2.find(2))->second) != s.end());
438         }
439         assert(c2.find(3)->second == "three");
440         assert(c2.find(4)->second == "four");
441         assert(c2.hash_function() == Hash(1));
442         assert(c2.key_eq() == Compare(1));
443         assert(c2.get_allocator() == Alloc(1));
444         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
445         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
446         assert(c2.max_load_factor() == 1);
447     }
448 #if TEST_STD_VER >= 11
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         C c1(0, Hash(1), Compare(1), Alloc());
455         C c2(0, Hash(2), Compare(2), Alloc());
456         c2.max_load_factor(2);
457         c1.swap(c2);
458 
459         LIBCPP_ASSERT(c1.bucket_count() == 0);
460         assert(c1.size() == 0);
461         assert(c1.hash_function() == Hash(2));
462         assert(c1.key_eq() == Compare(2));
463         assert(c1.get_allocator() == Alloc());
464         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
465         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
466         assert(c1.max_load_factor() == 2);
467 
468         LIBCPP_ASSERT(c2.bucket_count() == 0);
469         assert(c2.size() == 0);
470         assert(c2.hash_function() == Hash(1));
471         assert(c2.key_eq() == Compare(1));
472         assert(c2.get_allocator() == Alloc());
473         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
474         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
475         assert(c2.max_load_factor() == 1);
476     }
477     {
478         typedef test_hash<int> Hash;
479         typedef test_equal_to<int> Compare;
480         typedef min_allocator<std::pair<const int, std::string> > Alloc;
481         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
482         typedef std::pair<int, std::string> P;
483         P a2[] =
484         {
485             P(10, "ten"),
486             P(20, "twenty"),
487             P(30, "thirty"),
488             P(40, "forty"),
489             P(50, "fifty"),
490             P(60, "sixty"),
491             P(70, "seventy"),
492             P(80, "eighty"),
493         };
494         C c1(0, Hash(1), Compare(1), Alloc());
495         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc());
496         c2.max_load_factor(2);
497         c1.swap(c2);
498 
499         assert(c1.bucket_count() >= 8);
500         assert(c1.size() == 8);
501         assert(c1.find(10)->second == "ten");
502         assert(c1.find(20)->second == "twenty");
503         assert(c1.find(30)->second == "thirty");
504         assert(c1.find(40)->second == "forty");
505         assert(c1.find(50)->second == "fifty");
506         assert(c1.find(60)->second == "sixty");
507         assert(c1.find(70)->second == "seventy");
508         assert(c1.find(80)->second == "eighty");
509         assert(c1.hash_function() == Hash(2));
510         assert(c1.key_eq() == Compare(2));
511         assert(c1.get_allocator() == Alloc());
512         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
513         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
514         assert(c1.max_load_factor() == 2);
515 
516         LIBCPP_ASSERT(c2.bucket_count() == 0);
517         assert(c2.size() == 0);
518         assert(c2.hash_function() == Hash(1));
519         assert(c2.key_eq() == Compare(1));
520         assert(c2.get_allocator() == Alloc());
521         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
522         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
523         assert(c2.max_load_factor() == 1);
524     }
525     {
526         typedef test_hash<int> Hash;
527         typedef test_equal_to<int> Compare;
528         typedef min_allocator<std::pair<const int, std::string> > Alloc;
529         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
530         typedef std::pair<int, std::string> P;
531         P a1[] =
532         {
533             P(1, "one"),
534             P(2, "two"),
535             P(3, "three"),
536             P(4, "four"),
537             P(1, "four"),
538             P(2, "four"),
539         };
540         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc());
541         C c2(0, Hash(2), Compare(2), Alloc());
542         c2.max_load_factor(2);
543         c1.swap(c2);
544 
545         LIBCPP_ASSERT(c1.bucket_count() == 0);
546         assert(c1.size() == 0);
547         assert(c1.hash_function() == Hash(2));
548         assert(c1.key_eq() == Compare(2));
549         assert(c1.get_allocator() == Alloc());
550         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
551         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
552         assert(c1.max_load_factor() == 2);
553 
554         assert(c2.bucket_count() >= 6);
555         assert(c2.size() == 6);
556         {
557             std::set<std::string> s;
558             s.insert("one");
559             s.insert("four");
560             assert(s.find(c2.find(1)->second) != s.end());
561             s.erase(s.find(c2.find(1)->second));
562             assert(s.find(std::next(c2.find(1))->second) != s.end());
563         }
564         {
565             std::set<std::string> s;
566             s.insert("two");
567             s.insert("four");
568             assert(s.find(c2.find(2)->second) != s.end());
569             s.erase(s.find(c2.find(2)->second));
570             assert(s.find(std::next(c2.find(2))->second) != s.end());
571         }
572         assert(c2.find(3)->second == "three");
573         assert(c2.find(4)->second == "four");
574         assert(c2.hash_function() == Hash(1));
575         assert(c2.key_eq() == Compare(1));
576         assert(c2.get_allocator() == Alloc());
577         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
578         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
579         assert(c2.max_load_factor() == 1);
580     }
581     {
582         typedef test_hash<int> Hash;
583         typedef test_equal_to<int> Compare;
584         typedef min_allocator<std::pair<const int, std::string> > Alloc;
585         typedef std::unordered_multimap<int, std::string, Hash, Compare, Alloc> C;
586         typedef std::pair<int, std::string> P;
587         P a1[] =
588         {
589             P(1, "one"),
590             P(2, "two"),
591             P(3, "three"),
592             P(4, "four"),
593             P(1, "four"),
594             P(2, "four"),
595         };
596         P a2[] =
597         {
598             P(10, "ten"),
599             P(20, "twenty"),
600             P(30, "thirty"),
601             P(40, "forty"),
602             P(50, "fifty"),
603             P(60, "sixty"),
604             P(70, "seventy"),
605             P(80, "eighty"),
606         };
607         C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc());
608         C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc());
609         c2.max_load_factor(2);
610         c1.swap(c2);
611 
612         assert(c1.bucket_count() >= 8);
613         assert(c1.size() == 8);
614         assert(c1.find(10)->second == "ten");
615         assert(c1.find(20)->second == "twenty");
616         assert(c1.find(30)->second == "thirty");
617         assert(c1.find(40)->second == "forty");
618         assert(c1.find(50)->second == "fifty");
619         assert(c1.find(60)->second == "sixty");
620         assert(c1.find(70)->second == "seventy");
621         assert(c1.find(80)->second == "eighty");
622         assert(c1.hash_function() == Hash(2));
623         assert(c1.key_eq() == Compare(2));
624         assert(c1.get_allocator() == Alloc());
625         assert(static_cast<std::size_t>(std::distance(c1.begin(), c1.end())) == c1.size());
626         assert(static_cast<std::size_t>(std::distance(c1.cbegin(), c1.cend())) == c1.size());
627         assert(c1.max_load_factor() == 2);
628 
629         assert(c2.bucket_count() >= 6);
630         assert(c2.size() == 6);
631         {
632             std::set<std::string> s;
633             s.insert("one");
634             s.insert("four");
635             assert(s.find(c2.find(1)->second) != s.end());
636             s.erase(s.find(c2.find(1)->second));
637             assert(s.find(std::next(c2.find(1))->second) != s.end());
638         }
639         {
640             std::set<std::string> s;
641             s.insert("two");
642             s.insert("four");
643             assert(s.find(c2.find(2)->second) != s.end());
644             s.erase(s.find(c2.find(2)->second));
645             assert(s.find(std::next(c2.find(2))->second) != s.end());
646         }
647         assert(c2.find(3)->second == "three");
648         assert(c2.find(4)->second == "four");
649         assert(c2.hash_function() == Hash(1));
650         assert(c2.key_eq() == Compare(1));
651         assert(c2.get_allocator() == Alloc());
652         assert(static_cast<std::size_t>(std::distance(c2.begin(), c2.end())) == c2.size());
653         assert(static_cast<std::size_t>(std::distance(c2.cbegin(), c2.cend())) == c2.size());
654         assert(c2.max_load_factor() == 1);
655     }
656 #endif
657 
658   return 0;
659 }
660