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_map
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>
26 #include "test_macros.h"
27 #include "min_allocator.h"
32 typedef std::unordered_map
<int, std::string
> C
;
33 typedef std::pair
<int, std::string
> P
;
34 typedef C::local_iterator I
;
44 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
45 assert(c
.bucket_count() >= 5);
46 C::size_type b
= c
.bucket(0);
49 assert(std::distance(i
, j
) == 0);
54 assert(std::distance(i
, j
) == 1);
55 assert(i
->first
== 1);
56 assert(i
->second
== "one");
61 assert(std::distance(i
, j
) == 1);
62 assert(i
->first
== 2);
63 assert(i
->second
== "two");
68 assert(std::distance(i
, j
) == 1);
69 assert(i
->first
== 3);
70 assert(i
->second
== "three");
75 assert(std::distance(i
, j
) == 1);
76 assert(i
->first
== 4);
77 assert(i
->second
== "four");
80 typedef std::unordered_map
<int, std::string
> C
;
81 typedef std::pair
<int, std::string
> P
;
82 typedef C::const_local_iterator I
;
92 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
93 assert(c
.bucket_count() >= 5);
94 C::size_type b
= c
.bucket(0);
97 assert(std::distance(i
, j
) == 0);
102 assert(std::distance(i
, j
) == 1);
103 assert(i
->first
== 1);
104 assert(i
->second
== "one");
109 assert(std::distance(i
, j
) == 1);
110 assert(i
->first
== 2);
111 assert(i
->second
== "two");
116 assert(std::distance(i
, j
) == 1);
117 assert(i
->first
== 3);
118 assert(i
->second
== "three");
123 assert(std::distance(i
, j
) == 1);
124 assert(i
->first
== 4);
125 assert(i
->second
== "four");
128 typedef std::unordered_map
<int, std::string
> C
;
129 typedef std::pair
<int, std::string
> P
;
130 typedef C::const_local_iterator I
;
140 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
141 assert(c
.bucket_count() >= 5);
142 C::size_type b
= c
.bucket(0);
145 assert(std::distance(i
, j
) == 0);
150 assert(std::distance(i
, j
) == 1);
151 assert(i
->first
== 1);
152 assert(i
->second
== "one");
157 assert(std::distance(i
, j
) == 1);
158 assert(i
->first
== 2);
159 assert(i
->second
== "two");
164 assert(std::distance(i
, j
) == 1);
165 assert(i
->first
== 3);
166 assert(i
->second
== "three");
171 assert(std::distance(i
, j
) == 1);
172 assert(i
->first
== 4);
173 assert(i
->second
== "four");
176 typedef std::unordered_map
<int, std::string
> C
;
177 typedef std::pair
<int, std::string
> P
;
178 typedef C::const_local_iterator I
;
188 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
189 assert(c
.bucket_count() >= 5);
190 C::size_type b
= c
.bucket(0);
193 assert(std::distance(i
, j
) == 0);
198 assert(std::distance(i
, j
) == 1);
199 assert(i
->first
== 1);
200 assert(i
->second
== "one");
205 assert(std::distance(i
, j
) == 1);
206 assert(i
->first
== 2);
207 assert(i
->second
== "two");
212 assert(std::distance(i
, j
) == 1);
213 assert(i
->first
== 3);
214 assert(i
->second
== "three");
219 assert(std::distance(i
, j
) == 1);
220 assert(i
->first
== 4);
221 assert(i
->second
== "four");
223 #if TEST_STD_VER >= 11
225 typedef std::unordered_map
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
226 min_allocator
<std::pair
<const int, std::string
>>> C
;
227 typedef std::pair
<int, std::string
> P
;
228 typedef C::local_iterator I
;
238 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
239 assert(c
.bucket_count() >= 5);
240 C::size_type b
= c
.bucket(0);
243 assert(std::distance(i
, j
) == 0);
248 assert(std::distance(i
, j
) == 1);
249 assert(i
->first
== 1);
250 assert(i
->second
== "one");
255 assert(std::distance(i
, j
) == 1);
256 assert(i
->first
== 2);
257 assert(i
->second
== "two");
262 assert(std::distance(i
, j
) == 1);
263 assert(i
->first
== 3);
264 assert(i
->second
== "three");
269 assert(std::distance(i
, j
) == 1);
270 assert(i
->first
== 4);
271 assert(i
->second
== "four");
274 typedef std::unordered_map
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
275 min_allocator
<std::pair
<const int, std::string
>>> C
;
276 typedef std::pair
<int, std::string
> P
;
277 typedef C::const_local_iterator I
;
287 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
288 assert(c
.bucket_count() >= 5);
289 C::size_type b
= c
.bucket(0);
292 assert(std::distance(i
, j
) == 0);
297 assert(std::distance(i
, j
) == 1);
298 assert(i
->first
== 1);
299 assert(i
->second
== "one");
304 assert(std::distance(i
, j
) == 1);
305 assert(i
->first
== 2);
306 assert(i
->second
== "two");
311 assert(std::distance(i
, j
) == 1);
312 assert(i
->first
== 3);
313 assert(i
->second
== "three");
318 assert(std::distance(i
, j
) == 1);
319 assert(i
->first
== 4);
320 assert(i
->second
== "four");
323 typedef std::unordered_map
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
324 min_allocator
<std::pair
<const int, std::string
>>> C
;
325 typedef std::pair
<int, std::string
> P
;
326 typedef C::const_local_iterator I
;
336 C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
337 assert(c
.bucket_count() >= 5);
338 C::size_type b
= c
.bucket(0);
341 assert(std::distance(i
, j
) == 0);
346 assert(std::distance(i
, j
) == 1);
347 assert(i
->first
== 1);
348 assert(i
->second
== "one");
353 assert(std::distance(i
, j
) == 1);
354 assert(i
->first
== 2);
355 assert(i
->second
== "two");
360 assert(std::distance(i
, j
) == 1);
361 assert(i
->first
== 3);
362 assert(i
->second
== "three");
367 assert(std::distance(i
, j
) == 1);
368 assert(i
->first
== 4);
369 assert(i
->second
== "four");
372 typedef std::unordered_map
<int, std::string
, std::hash
<int>, std::equal_to
<int>,
373 min_allocator
<std::pair
<const int, std::string
>>> C
;
374 typedef std::pair
<int, std::string
> P
;
375 typedef C::const_local_iterator I
;
385 const C
c(a
, a
+ sizeof(a
)/sizeof(a
[0]));
386 assert(c
.bucket_count() >= 5);
387 C::size_type b
= c
.bucket(0);
390 assert(std::distance(i
, j
) == 0);
395 assert(std::distance(i
, j
) == 1);
396 assert(i
->first
== 1);
397 assert(i
->second
== "one");
402 assert(std::distance(i
, j
) == 1);
403 assert(i
->first
== 2);
404 assert(i
->second
== "two");
409 assert(std::distance(i
, j
) == 1);
410 assert(i
->first
== 3);
411 assert(i
->second
== "three");
416 assert(std::distance(i
, j
) == 1);
417 assert(i
->first
== 4);
418 assert(i
->second
== "four");