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

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