Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / unord / unord.map / local_iterators.pass.cpp
blob5da3a0b3d932c4748e445e992a7e01756e22fcb4
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 //===----------------------------------------------------------------------===//
9 // <unordered_map>
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>
23 #include <string>
24 #include <cassert>
26 #include "test_macros.h"
27 #include "min_allocator.h"
29 int main(int, char**)
32 typedef std::unordered_map<int, std::string> C;
33 typedef std::pair<int, std::string> P;
34 typedef C::local_iterator I;
35 P a[] =
37 P(1, "one"),
38 P(2, "two"),
39 P(3, "three"),
40 P(4, "four"),
41 P(1, "four"),
42 P(2, "four"),
44 C c(a, a + sizeof(a)/sizeof(a[0]));
45 assert(c.bucket_count() >= 5);
46 C::size_type b = c.bucket(0);
47 I i = c.begin(b);
48 I j = c.end(b);
49 assert(std::distance(i, j) == 0);
51 b = c.bucket(1);
52 i = c.begin(b);
53 j = c.end(b);
54 assert(std::distance(i, j) == 1);
55 assert(i->first == 1);
56 assert(i->second == "one");
58 b = c.bucket(2);
59 i = c.begin(b);
60 j = c.end(b);
61 assert(std::distance(i, j) == 1);
62 assert(i->first == 2);
63 assert(i->second == "two");
65 b = c.bucket(3);
66 i = c.begin(b);
67 j = c.end(b);
68 assert(std::distance(i, j) == 1);
69 assert(i->first == 3);
70 assert(i->second == "three");
72 b = c.bucket(4);
73 i = c.begin(b);
74 j = c.end(b);
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;
83 P a[] =
85 P(1, "one"),
86 P(2, "two"),
87 P(3, "three"),
88 P(4, "four"),
89 P(1, "four"),
90 P(2, "four"),
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);
95 I i = c.begin(b);
96 I j = c.end(b);
97 assert(std::distance(i, j) == 0);
99 b = c.bucket(1);
100 i = c.begin(b);
101 j = c.end(b);
102 assert(std::distance(i, j) == 1);
103 assert(i->first == 1);
104 assert(i->second == "one");
106 b = c.bucket(2);
107 i = c.begin(b);
108 j = c.end(b);
109 assert(std::distance(i, j) == 1);
110 assert(i->first == 2);
111 assert(i->second == "two");
113 b = c.bucket(3);
114 i = c.begin(b);
115 j = c.end(b);
116 assert(std::distance(i, j) == 1);
117 assert(i->first == 3);
118 assert(i->second == "three");
120 b = c.bucket(4);
121 i = c.begin(b);
122 j = c.end(b);
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;
131 P a[] =
133 P(1, "one"),
134 P(2, "two"),
135 P(3, "three"),
136 P(4, "four"),
137 P(1, "four"),
138 P(2, "four"),
140 C c(a, a + sizeof(a)/sizeof(a[0]));
141 assert(c.bucket_count() >= 5);
142 C::size_type b = c.bucket(0);
143 I i = c.cbegin(b);
144 I j = c.cend(b);
145 assert(std::distance(i, j) == 0);
147 b = c.bucket(1);
148 i = c.cbegin(b);
149 j = c.cend(b);
150 assert(std::distance(i, j) == 1);
151 assert(i->first == 1);
152 assert(i->second == "one");
154 b = c.bucket(2);
155 i = c.cbegin(b);
156 j = c.cend(b);
157 assert(std::distance(i, j) == 1);
158 assert(i->first == 2);
159 assert(i->second == "two");
161 b = c.bucket(3);
162 i = c.cbegin(b);
163 j = c.cend(b);
164 assert(std::distance(i, j) == 1);
165 assert(i->first == 3);
166 assert(i->second == "three");
168 b = c.bucket(4);
169 i = c.cbegin(b);
170 j = c.cend(b);
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;
179 P a[] =
181 P(1, "one"),
182 P(2, "two"),
183 P(3, "three"),
184 P(4, "four"),
185 P(1, "four"),
186 P(2, "four"),
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);
191 I i = c.cbegin(b);
192 I j = c.cend(b);
193 assert(std::distance(i, j) == 0);
195 b = c.bucket(1);
196 i = c.cbegin(b);
197 j = c.cend(b);
198 assert(std::distance(i, j) == 1);
199 assert(i->first == 1);
200 assert(i->second == "one");
202 b = c.bucket(2);
203 i = c.cbegin(b);
204 j = c.cend(b);
205 assert(std::distance(i, j) == 1);
206 assert(i->first == 2);
207 assert(i->second == "two");
209 b = c.bucket(3);
210 i = c.cbegin(b);
211 j = c.cend(b);
212 assert(std::distance(i, j) == 1);
213 assert(i->first == 3);
214 assert(i->second == "three");
216 b = c.bucket(4);
217 i = c.cbegin(b);
218 j = c.cend(b);
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;
229 P a[] =
231 P(1, "one"),
232 P(2, "two"),
233 P(3, "three"),
234 P(4, "four"),
235 P(1, "four"),
236 P(2, "four"),
238 C c(a, a + sizeof(a)/sizeof(a[0]));
239 assert(c.bucket_count() >= 5);
240 C::size_type b = c.bucket(0);
241 I i = c.begin(b);
242 I j = c.end(b);
243 assert(std::distance(i, j) == 0);
245 b = c.bucket(1);
246 i = c.begin(b);
247 j = c.end(b);
248 assert(std::distance(i, j) == 1);
249 assert(i->first == 1);
250 assert(i->second == "one");
252 b = c.bucket(2);
253 i = c.begin(b);
254 j = c.end(b);
255 assert(std::distance(i, j) == 1);
256 assert(i->first == 2);
257 assert(i->second == "two");
259 b = c.bucket(3);
260 i = c.begin(b);
261 j = c.end(b);
262 assert(std::distance(i, j) == 1);
263 assert(i->first == 3);
264 assert(i->second == "three");
266 b = c.bucket(4);
267 i = c.begin(b);
268 j = c.end(b);
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;
278 P a[] =
280 P(1, "one"),
281 P(2, "two"),
282 P(3, "three"),
283 P(4, "four"),
284 P(1, "four"),
285 P(2, "four"),
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);
290 I i = c.begin(b);
291 I j = c.end(b);
292 assert(std::distance(i, j) == 0);
294 b = c.bucket(1);
295 i = c.begin(b);
296 j = c.end(b);
297 assert(std::distance(i, j) == 1);
298 assert(i->first == 1);
299 assert(i->second == "one");
301 b = c.bucket(2);
302 i = c.begin(b);
303 j = c.end(b);
304 assert(std::distance(i, j) == 1);
305 assert(i->first == 2);
306 assert(i->second == "two");
308 b = c.bucket(3);
309 i = c.begin(b);
310 j = c.end(b);
311 assert(std::distance(i, j) == 1);
312 assert(i->first == 3);
313 assert(i->second == "three");
315 b = c.bucket(4);
316 i = c.begin(b);
317 j = c.end(b);
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;
327 P a[] =
329 P(1, "one"),
330 P(2, "two"),
331 P(3, "three"),
332 P(4, "four"),
333 P(1, "four"),
334 P(2, "four"),
336 C c(a, a + sizeof(a)/sizeof(a[0]));
337 assert(c.bucket_count() >= 5);
338 C::size_type b = c.bucket(0);
339 I i = c.cbegin(b);
340 I j = c.cend(b);
341 assert(std::distance(i, j) == 0);
343 b = c.bucket(1);
344 i = c.cbegin(b);
345 j = c.cend(b);
346 assert(std::distance(i, j) == 1);
347 assert(i->first == 1);
348 assert(i->second == "one");
350 b = c.bucket(2);
351 i = c.cbegin(b);
352 j = c.cend(b);
353 assert(std::distance(i, j) == 1);
354 assert(i->first == 2);
355 assert(i->second == "two");
357 b = c.bucket(3);
358 i = c.cbegin(b);
359 j = c.cend(b);
360 assert(std::distance(i, j) == 1);
361 assert(i->first == 3);
362 assert(i->second == "three");
364 b = c.bucket(4);
365 i = c.cbegin(b);
366 j = c.cend(b);
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;
376 P a[] =
378 P(1, "one"),
379 P(2, "two"),
380 P(3, "three"),
381 P(4, "four"),
382 P(1, "four"),
383 P(2, "four"),
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);
388 I i = c.cbegin(b);
389 I j = c.cend(b);
390 assert(std::distance(i, j) == 0);
392 b = c.bucket(1);
393 i = c.cbegin(b);
394 j = c.cend(b);
395 assert(std::distance(i, j) == 1);
396 assert(i->first == 1);
397 assert(i->second == "one");
399 b = c.bucket(2);
400 i = c.cbegin(b);
401 j = c.cend(b);
402 assert(std::distance(i, j) == 1);
403 assert(i->first == 2);
404 assert(i->second == "two");
406 b = c.bucket(3);
407 i = c.cbegin(b);
408 j = c.cend(b);
409 assert(std::distance(i, j) == 1);
410 assert(i->first == 3);
411 assert(i->second == "three");
413 b = c.bucket(4);
414 i = c.cbegin(b);
415 j = c.cend(b);
416 assert(std::distance(i, j) == 1);
417 assert(i->first == 4);
418 assert(i->second == "four");
420 #endif
422 return 0;