1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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
15 // local_iterator begin (size_type n);
16 // local_iterator end (size_type n);
17 // const_local_iterator begin (size_type n) const;
18 // const_local_iterator end (size_type n) const;
19 // const_local_iterator cbegin(size_type n) const;
20 // const_local_iterator cend (size_type n) const;
22 #include <unordered_map>
27 #include "test_macros.h"
28 #include "min_allocator.h"
33 typedef std::unordered_multimap
<int, std::string
> C
;
34 typedef std::pair
<int, std::string
> P
;
35 typedef C::local_iterator I
;
45 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
46 assert(c
.bucket_count() >= 7);
47 C::size_type b
= c
.bucket(0);
50 assert(std::distance(i
, j
) == 0);
55 assert(std::distance(i
, j
) == 2);
57 std::set
<std::string
> s
;
60 for ( int n
= 0; n
< 2; ++n
)
62 assert(i
->first
== 1);
63 assert(s
.find(i
->second
) != s
.end());
64 s
.erase(s
.find(i
->second
));
72 assert(std::distance(i
, j
) == 2);
74 std::set
<std::string
> s
;
77 for ( int n
= 0; n
< 2; ++n
)
79 assert(i
->first
== 2);
80 assert(s
.find(i
->second
) != s
.end());
81 s
.erase(s
.find(i
->second
));
89 assert(std::distance(i
, j
) == 1);
90 assert(i
->first
== 3);
91 assert(i
->second
== "three");
96 assert(std::distance(i
, j
) == 1);
97 assert(i
->first
== 4);
98 assert(i
->second
== "four");
103 assert(std::distance(i
, j
) == 0);
108 assert(std::distance(i
, j
) == 0);
111 typedef std::unordered_multimap
<int, std::string
> C
;
112 typedef std::pair
<int, std::string
> P
;
113 typedef C::const_local_iterator I
;
123 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
124 assert(c
.bucket_count() >= 7);
125 C::size_type b
= c
.bucket(0);
128 assert(std::distance(i
, j
) == 0);
133 assert(std::distance(i
, j
) == 2);
135 std::set
<std::string
> s
;
138 for ( int n
= 0; n
< 2; ++n
)
140 assert(i
->first
== 1);
141 assert(s
.find(i
->second
) != s
.end());
142 s
.erase(s
.find(i
->second
));
150 assert(std::distance(i
, j
) == 2);
152 std::set
<std::string
> s
;
155 for ( int n
= 0; n
< 2; ++n
)
157 assert(i
->first
== 2);
158 assert(s
.find(i
->second
) != s
.end());
159 s
.erase(s
.find(i
->second
));
167 assert(std::distance(i
, j
) == 1);
168 assert(i
->first
== 3);
169 assert(i
->second
== "three");
174 assert(std::distance(i
, j
) == 1);
175 assert(i
->first
== 4);
176 assert(i
->second
== "four");
181 assert(std::distance(i
, j
) == 0);
186 assert(std::distance(i
, j
) == 0);
189 typedef std::unordered_multimap
<int, std::string
> C
;
190 typedef std::pair
<int, std::string
> P
;
191 typedef C::const_local_iterator I
;
201 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
202 assert(c
.bucket_count() >= 7);
203 C::size_type b
= c
.bucket(0);
206 assert(std::distance(i
, j
) == 0);
211 assert(std::distance(i
, j
) == 2);
213 std::set
<std::string
> s
;
216 for ( int n
= 0; n
< 2; ++n
)
218 assert(i
->first
== 1);
219 assert(s
.find(i
->second
) != s
.end());
220 s
.erase(s
.find(i
->second
));
228 assert(std::distance(i
, j
) == 2);
230 std::set
<std::string
> s
;
233 for ( int n
= 0; n
< 2; ++n
)
235 assert(i
->first
== 2);
236 assert(s
.find(i
->second
) != s
.end());
237 s
.erase(s
.find(i
->second
));
245 assert(std::distance(i
, j
) == 1);
246 assert(i
->first
== 3);
247 assert(i
->second
== "three");
252 assert(std::distance(i
, j
) == 1);
253 assert(i
->first
== 4);
254 assert(i
->second
== "four");
259 assert(std::distance(i
, j
) == 0);
264 assert(std::distance(i
, j
) == 0);
267 typedef std::unordered_multimap
<int, std::string
> C
;
268 typedef std::pair
<int, std::string
> P
;
269 typedef C::const_local_iterator I
;
279 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
280 assert(c
.bucket_count() >= 7);
281 C::size_type b
= c
.bucket(0);
284 assert(std::distance(i
, j
) == 0);
289 assert(std::distance(i
, j
) == 2);
291 std::set
<std::string
> s
;
294 for ( int n
= 0; n
< 2; ++n
)
296 assert(i
->first
== 1);
297 assert(s
.find(i
->second
) != s
.end());
298 s
.erase(s
.find(i
->second
));
306 assert(std::distance(i
, j
) == 2);
308 std::set
<std::string
> s
;
311 for ( int n
= 0; n
< 2; ++n
)
313 assert(i
->first
== 2);
314 assert(s
.find(i
->second
) != s
.end());
315 s
.erase(s
.find(i
->second
));
323 assert(std::distance(i
, j
) == 1);
324 assert(i
->first
== 3);
325 assert(i
->second
== "three");
330 assert(std::distance(i
, j
) == 1);
331 assert(i
->first
== 4);
332 assert(i
->second
== "four");
337 assert(std::distance(i
, j
) == 0);
342 assert(std::distance(i
, j
) == 0);
344 #if TEST_STD_VER >= 11
346 typedef std::unordered_multimap
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
347 min_allocator
<std::pair
<const int, std::string
>>> C
;
348 typedef std::pair
<int, std::string
> P
;
349 typedef C::local_iterator I
;
359 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
360 assert(c
.bucket_count() >= 7);
361 C::size_type b
= c
.bucket(0);
364 assert(std::distance(i
, j
) == 0);
369 assert(std::distance(i
, j
) == 2);
371 std::set
<std::string
> s
;
374 for ( int n
= 0; n
< 2; ++n
)
376 assert(i
->first
== 1);
377 assert(s
.find(i
->second
) != s
.end());
378 s
.erase(s
.find(i
->second
));
386 assert(std::distance(i
, j
) == 2);
388 std::set
<std::string
> s
;
391 for ( int n
= 0; n
< 2; ++n
)
393 assert(i
->first
== 2);
394 assert(s
.find(i
->second
) != s
.end());
395 s
.erase(s
.find(i
->second
));
403 assert(std::distance(i
, j
) == 1);
404 assert(i
->first
== 3);
405 assert(i
->second
== "three");
410 assert(std::distance(i
, j
) == 1);
411 assert(i
->first
== 4);
412 assert(i
->second
== "four");
417 assert(std::distance(i
, j
) == 0);
422 assert(std::distance(i
, j
) == 0);
425 typedef std::unordered_multimap
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
426 min_allocator
<std::pair
<const int, std::string
>>> C
;
427 typedef std::pair
<int, std::string
> P
;
428 typedef C::const_local_iterator I
;
438 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
439 assert(c
.bucket_count() >= 7);
440 C::size_type b
= c
.bucket(0);
443 assert(std::distance(i
, j
) == 0);
448 assert(std::distance(i
, j
) == 2);
450 std::set
<std::string
> s
;
453 for ( int n
= 0; n
< 2; ++n
)
455 assert(i
->first
== 1);
456 assert(s
.find(i
->second
) != s
.end());
457 s
.erase(s
.find(i
->second
));
465 assert(std::distance(i
, j
) == 2);
467 std::set
<std::string
> s
;
470 for ( int n
= 0; n
< 2; ++n
)
472 assert(i
->first
== 2);
473 assert(s
.find(i
->second
) != s
.end());
474 s
.erase(s
.find(i
->second
));
482 assert(std::distance(i
, j
) == 1);
483 assert(i
->first
== 3);
484 assert(i
->second
== "three");
489 assert(std::distance(i
, j
) == 1);
490 assert(i
->first
== 4);
491 assert(i
->second
== "four");
496 assert(std::distance(i
, j
) == 0);
501 assert(std::distance(i
, j
) == 0);
504 typedef std::unordered_multimap
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
505 min_allocator
<std::pair
<const int, std::string
>>> C
;
506 typedef std::pair
<int, std::string
> P
;
507 typedef C::const_local_iterator I
;
517 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
518 assert(c
.bucket_count() >= 7);
519 C::size_type b
= c
.bucket(0);
522 assert(std::distance(i
, j
) == 0);
527 assert(std::distance(i
, j
) == 2);
529 std::set
<std::string
> s
;
532 for ( int n
= 0; n
< 2; ++n
)
534 assert(i
->first
== 1);
535 assert(s
.find(i
->second
) != s
.end());
536 s
.erase(s
.find(i
->second
));
544 assert(std::distance(i
, j
) == 2);
546 std::set
<std::string
> s
;
549 for ( int n
= 0; n
< 2; ++n
)
551 assert(i
->first
== 2);
552 assert(s
.find(i
->second
) != s
.end());
553 s
.erase(s
.find(i
->second
));
561 assert(std::distance(i
, j
) == 1);
562 assert(i
->first
== 3);
563 assert(i
->second
== "three");
568 assert(std::distance(i
, j
) == 1);
569 assert(i
->first
== 4);
570 assert(i
->second
== "four");
575 assert(std::distance(i
, j
) == 0);
580 assert(std::distance(i
, j
) == 0);
583 typedef std::unordered_multimap
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
584 min_allocator
<std::pair
<const int, std::string
>>> C
;
585 typedef std::pair
<int, std::string
> P
;
586 typedef C::const_local_iterator I
;
596 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
597 assert(c
.bucket_count() >= 7);
598 C::size_type b
= c
.bucket(0);
601 assert(std::distance(i
, j
) == 0);
606 assert(std::distance(i
, j
) == 2);
608 std::set
<std::string
> s
;
611 for ( int n
= 0; n
< 2; ++n
)
613 assert(i
->first
== 1);
614 assert(s
.find(i
->second
) != s
.end());
615 s
.erase(s
.find(i
->second
));
623 assert(std::distance(i
, j
) == 2);
625 std::set
<std::string
> s
;
628 for ( int n
= 0; n
< 2; ++n
)
630 assert(i
->first
== 2);
631 assert(s
.find(i
->second
) != s
.end());
632 s
.erase(s
.find(i
->second
));
640 assert(std::distance(i
, j
) == 1);
641 assert(i
->first
== 3);
642 assert(i
->second
== "three");
647 assert(std::distance(i
, j
) == 1);
648 assert(i
->first
== 4);
649 assert(i
->second
== "four");
654 assert(std::distance(i
, j
) == 0);
659 assert(std::distance(i
, j
) == 0);