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// 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;
21
22#include <unordered_map>
23#include <string>
24#include <cassert>
25
26#include "test_macros.h"
27
28int main(int, char**)
29{
30 {
31 typedef std::unordered_multimap<int, std::string> C;
32 typedef std::pair<int, std::string> P;
33 typedef C::local_iterator I;
34 P a[] =
35 {
36 P(1, "one"),
37 P(2, "two"),
38 P(3, "three"),
39 P(4, "four"),
40 P(1, "four"),
41 P(2, "four"),
42 };
43 C c(a, a + sizeof(a)/sizeof(a[0]));
44 LIBCPP_ASSERT(c.bucket_count() == 7);
45 C::size_type b = c.bucket(key: 0);
46 I i = c.begin(b);
47 I j = c.end(b);
48 assert(std::distance(i, j) == 0);
49
50 b = c.bucket(key: 1);
51 i = c.begin(b);
52 j = c.end(b);
53 assert(std::distance(i, j) == 2);
54 assert(i->first == 1);
55 assert(i->second == "one");
56 ++i;
57 assert(i->first == 1);
58 assert(i->second == "four");
59 i->first = 2;
60
61 b = c.bucket(key: 2);
62 i = c.begin(b);
63 j = c.end(b);
64 assert(std::distance(i, j) == 2);
65 assert(i->first == 2);
66 assert(i->second == "two");
67 ++i;
68 assert(i->first == 2);
69 assert(i->second == "four");
70
71 b = c.bucket(key: 3);
72 i = c.begin(b);
73 j = c.end(b);
74 assert(std::distance(i, j) == 1);
75 assert(i->first == 3);
76 assert(i->second == "three");
77
78 b = c.bucket(key: 4);
79 i = c.begin(b);
80 j = c.end(b);
81 assert(std::distance(i, j) == 1);
82 assert(i->first == 4);
83 assert(i->second == "four");
84
85 b = c.bucket(key: 5);
86 i = c.begin(b);
87 j = c.end(b);
88 assert(std::distance(i, j) == 0);
89
90 b = c.bucket(key: 6);
91 i = c.begin(b);
92 j = c.end(b);
93 assert(std::distance(i, j) == 0);
94 }
95 {
96 typedef std::unordered_multimap<int, std::string> C;
97 typedef std::pair<int, std::string> P;
98 typedef C::const_local_iterator I;
99 P a[] =
100 {
101 P(1, "one"),
102 P(2, "two"),
103 P(3, "three"),
104 P(4, "four"),
105 P(1, "four"),
106 P(2, "four"),
107 };
108 const C c(a, a + sizeof(a)/sizeof(a[0]));
109 LIBCPP_ASSERT(c.bucket_count() == 7);
110 C::size_type b = c.bucket(0);
111 I i = c.begin(b);
112 I j = c.end(b);
113 assert(std::distance(i, j) == 0);
114
115 b = c.bucket(1);
116 i = c.begin(b);
117 j = c.end(b);
118 assert(std::distance(i, j) == 2);
119 assert(i->first == 1);
120 assert(i->second == "one");
121 ++i;
122 assert(i->first == 1);
123 assert(i->second == "four");
124
125 b = c.bucket(2);
126 i = c.begin(b);
127 j = c.end(b);
128 assert(std::distance(i, j) == 2);
129 assert(i->first == 2);
130 assert(i->second == "two");
131 ++i;
132 assert(i->first == 2);
133 assert(i->second == "four");
134
135 b = c.bucket(3);
136 i = c.begin(b);
137 j = c.end(b);
138 assert(std::distance(i, j) == 1);
139 assert(i->first == 3);
140 assert(i->second == "three");
141
142 b = c.bucket(4);
143 i = c.begin(b);
144 j = c.end(b);
145 assert(std::distance(i, j) == 1);
146 assert(i->first == 4);
147 assert(i->second == "four");
148
149 b = c.bucket(5);
150 i = c.begin(b);
151 j = c.end(b);
152 assert(std::distance(i, j) == 0);
153
154 b = c.bucket(6);
155 i = c.begin(b);
156 j = c.end(b);
157 assert(std::distance(i, j) == 0);
158 }
159 {
160 typedef std::unordered_multimap<int, std::string> C;
161 typedef std::pair<int, std::string> P;
162 typedef C::const_local_iterator I;
163 P a[] =
164 {
165 P(1, "one"),
166 P(2, "two"),
167 P(3, "three"),
168 P(4, "four"),
169 P(1, "four"),
170 P(2, "four"),
171 };
172 C c(a, a + sizeof(a)/sizeof(a[0]));
173 LIBCPP_ASSERT(c.bucket_count() == 7);
174 C::size_type b = c.bucket(0);
175 I i = c.cbegin(b);
176 I j = c.cend(b);
177 assert(std::distance(i, j) == 0);
178
179 b = c.bucket(1);
180 i = c.cbegin(b);
181 j = c.cend(b);
182 assert(std::distance(i, j) == 2);
183 assert(i->first == 1);
184 assert(i->second == "one");
185 ++i;
186 assert(i->first == 1);
187 assert(i->second == "four");
188
189 b = c.bucket(2);
190 i = c.cbegin(b);
191 j = c.cend(b);
192 assert(std::distance(i, j) == 2);
193 assert(i->first == 2);
194 assert(i->second == "two");
195 ++i;
196 assert(i->first == 2);
197 assert(i->second == "four");
198
199 b = c.bucket(3);
200 i = c.cbegin(b);
201 j = c.cend(b);
202 assert(std::distance(i, j) == 1);
203 assert(i->first == 3);
204 assert(i->second == "three");
205
206 b = c.bucket(4);
207 i = c.cbegin(b);
208 j = c.cend(b);
209 assert(std::distance(i, j) == 1);
210 assert(i->first == 4);
211 assert(i->second == "four");
212
213 b = c.bucket(5);
214 i = c.cbegin(b);
215 j = c.cend(b);
216 assert(std::distance(i, j) == 0);
217
218 b = c.bucket(6);
219 i = c.cbegin(b);
220 j = c.cend(b);
221 assert(std::distance(i, j) == 0);
222 }
223 {
224 typedef std::unordered_multimap<int, std::string> C;
225 typedef std::pair<int, std::string> P;
226 typedef C::const_local_iterator I;
227 P a[] =
228 {
229 P(1, "one"),
230 P(2, "two"),
231 P(3, "three"),
232 P(4, "four"),
233 P(1, "four"),
234 P(2, "four"),
235 };
236 const C c(a, a + sizeof(a)/sizeof(a[0]));
237 LIBCPP_ASSERT(c.bucket_count() == 7);
238 C::size_type b = c.bucket(0);
239 I i = c.cbegin(b);
240 I j = c.cend(b);
241 assert(std::distance(i, j) == 0);
242
243 b = c.bucket(1);
244 i = c.cbegin(b);
245 j = c.cend(b);
246 assert(std::distance(i, j) == 2);
247 assert(i->first == 1);
248 assert(i->second == "one");
249 ++i;
250 assert(i->first == 1);
251 assert(i->second == "four");
252
253 b = c.bucket(2);
254 i = c.cbegin(b);
255 j = c.cend(b);
256 assert(std::distance(i, j) == 2);
257 assert(i->first == 2);
258 assert(i->second == "two");
259 ++i;
260 assert(i->first == 2);
261 assert(i->second == "four");
262
263 b = c.bucket(3);
264 i = c.cbegin(b);
265 j = c.cend(b);
266 assert(std::distance(i, j) == 1);
267 assert(i->first == 3);
268 assert(i->second == "three");
269
270 b = c.bucket(4);
271 i = c.cbegin(b);
272 j = c.cend(b);
273 assert(std::distance(i, j) == 1);
274 assert(i->first == 4);
275 assert(i->second == "four");
276
277 b = c.bucket(5);
278 i = c.cbegin(b);
279 j = c.cend(b);
280 assert(std::distance(i, j) == 0);
281
282 b = c.bucket(6);
283 i = c.cbegin(b);
284 j = c.cend(b);
285 assert(std::distance(i, j) == 0);
286 }
287
288 return 0;
289}
290

source code of libcxx/test/std/containers/unord/unord.multimap/local_iterators.compile.fail.cpp