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