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

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