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 //===----------------------------------------------------------------------===//
13 // pair<iterator,iterator> equal_range(const key_type& k);
14 // pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
19 #include "test_macros.h"
20 #include "min_allocator.h"
21 #include "private_constructor.h"
27 typedef std::set
<int> M
;
29 typedef std::pair
<M::iterator
, M::iterator
> R
;
41 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
42 R r
= m
.equal_range(5);
43 assert(r
.first
== std::next(m
.begin(), 0));
44 assert(r
.second
== std::next(m
.begin(), 1));
46 assert(r
.first
== std::next(m
.begin(), 1));
47 assert(r
.second
== std::next(m
.begin(), 2));
49 assert(r
.first
== std::next(m
.begin(), 2));
50 assert(r
.second
== std::next(m
.begin(), 3));
51 r
= m
.equal_range(11);
52 assert(r
.first
== std::next(m
.begin(), 3));
53 assert(r
.second
== std::next(m
.begin(), 4));
54 r
= m
.equal_range(13);
55 assert(r
.first
== std::next(m
.begin(), 4));
56 assert(r
.second
== std::next(m
.begin(), 5));
57 r
= m
.equal_range(15);
58 assert(r
.first
== std::next(m
.begin(), 5));
59 assert(r
.second
== std::next(m
.begin(), 6));
60 r
= m
.equal_range(17);
61 assert(r
.first
== std::next(m
.begin(), 6));
62 assert(r
.second
== std::next(m
.begin(), 7));
63 r
= m
.equal_range(19);
64 assert(r
.first
== std::next(m
.begin(), 7));
65 assert(r
.second
== std::next(m
.begin(), 8));
67 assert(r
.first
== std::next(m
.begin(), 0));
68 assert(r
.second
== std::next(m
.begin(), 0));
70 assert(r
.first
== std::next(m
.begin(), 1));
71 assert(r
.second
== std::next(m
.begin(), 1));
73 assert(r
.first
== std::next(m
.begin(), 2));
74 assert(r
.second
== std::next(m
.begin(), 2));
75 r
= m
.equal_range(10);
76 assert(r
.first
== std::next(m
.begin(), 3));
77 assert(r
.second
== std::next(m
.begin(), 3));
78 r
= m
.equal_range(12);
79 assert(r
.first
== std::next(m
.begin(), 4));
80 assert(r
.second
== std::next(m
.begin(), 4));
81 r
= m
.equal_range(14);
82 assert(r
.first
== std::next(m
.begin(), 5));
83 assert(r
.second
== std::next(m
.begin(), 5));
84 r
= m
.equal_range(16);
85 assert(r
.first
== std::next(m
.begin(), 6));
86 assert(r
.second
== std::next(m
.begin(), 6));
87 r
= m
.equal_range(18);
88 assert(r
.first
== std::next(m
.begin(), 7));
89 assert(r
.second
== std::next(m
.begin(), 7));
90 r
= m
.equal_range(20);
91 assert(r
.first
== std::next(m
.begin(), 8));
92 assert(r
.second
== std::next(m
.begin(), 8));
95 typedef std::pair
<M::const_iterator
, M::const_iterator
> R
;
107 const M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
108 R r
= m
.equal_range(5);
109 assert(r
.first
== std::next(m
.begin(), 0));
110 assert(r
.second
== std::next(m
.begin(), 1));
111 r
= m
.equal_range(7);
112 assert(r
.first
== std::next(m
.begin(), 1));
113 assert(r
.second
== std::next(m
.begin(), 2));
114 r
= m
.equal_range(9);
115 assert(r
.first
== std::next(m
.begin(), 2));
116 assert(r
.second
== std::next(m
.begin(), 3));
117 r
= m
.equal_range(11);
118 assert(r
.first
== std::next(m
.begin(), 3));
119 assert(r
.second
== std::next(m
.begin(), 4));
120 r
= m
.equal_range(13);
121 assert(r
.first
== std::next(m
.begin(), 4));
122 assert(r
.second
== std::next(m
.begin(), 5));
123 r
= m
.equal_range(15);
124 assert(r
.first
== std::next(m
.begin(), 5));
125 assert(r
.second
== std::next(m
.begin(), 6));
126 r
= m
.equal_range(17);
127 assert(r
.first
== std::next(m
.begin(), 6));
128 assert(r
.second
== std::next(m
.begin(), 7));
129 r
= m
.equal_range(19);
130 assert(r
.first
== std::next(m
.begin(), 7));
131 assert(r
.second
== std::next(m
.begin(), 8));
132 r
= m
.equal_range(4);
133 assert(r
.first
== std::next(m
.begin(), 0));
134 assert(r
.second
== std::next(m
.begin(), 0));
135 r
= m
.equal_range(6);
136 assert(r
.first
== std::next(m
.begin(), 1));
137 assert(r
.second
== std::next(m
.begin(), 1));
138 r
= m
.equal_range(8);
139 assert(r
.first
== std::next(m
.begin(), 2));
140 assert(r
.second
== std::next(m
.begin(), 2));
141 r
= m
.equal_range(10);
142 assert(r
.first
== std::next(m
.begin(), 3));
143 assert(r
.second
== std::next(m
.begin(), 3));
144 r
= m
.equal_range(12);
145 assert(r
.first
== std::next(m
.begin(), 4));
146 assert(r
.second
== std::next(m
.begin(), 4));
147 r
= m
.equal_range(14);
148 assert(r
.first
== std::next(m
.begin(), 5));
149 assert(r
.second
== std::next(m
.begin(), 5));
150 r
= m
.equal_range(16);
151 assert(r
.first
== std::next(m
.begin(), 6));
152 assert(r
.second
== std::next(m
.begin(), 6));
153 r
= m
.equal_range(18);
154 assert(r
.first
== std::next(m
.begin(), 7));
155 assert(r
.second
== std::next(m
.begin(), 7));
156 r
= m
.equal_range(20);
157 assert(r
.first
== std::next(m
.begin(), 8));
158 assert(r
.second
== std::next(m
.begin(), 8));
161 #if TEST_STD_VER >= 11
164 typedef std::set
<int, std::less
<int>, min_allocator
<int>> M
;
165 typedef std::pair
<M::iterator
, M::iterator
> R
;
177 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
178 R r
= m
.equal_range(5);
179 assert(r
.first
== std::next(m
.begin(), 0));
180 assert(r
.second
== std::next(m
.begin(), 1));
181 r
= m
.equal_range(7);
182 assert(r
.first
== std::next(m
.begin(), 1));
183 assert(r
.second
== std::next(m
.begin(), 2));
184 r
= m
.equal_range(9);
185 assert(r
.first
== std::next(m
.begin(), 2));
186 assert(r
.second
== std::next(m
.begin(), 3));
187 r
= m
.equal_range(11);
188 assert(r
.first
== std::next(m
.begin(), 3));
189 assert(r
.second
== std::next(m
.begin(), 4));
190 r
= m
.equal_range(13);
191 assert(r
.first
== std::next(m
.begin(), 4));
192 assert(r
.second
== std::next(m
.begin(), 5));
193 r
= m
.equal_range(15);
194 assert(r
.first
== std::next(m
.begin(), 5));
195 assert(r
.second
== std::next(m
.begin(), 6));
196 r
= m
.equal_range(17);
197 assert(r
.first
== std::next(m
.begin(), 6));
198 assert(r
.second
== std::next(m
.begin(), 7));
199 r
= m
.equal_range(19);
200 assert(r
.first
== std::next(m
.begin(), 7));
201 assert(r
.second
== std::next(m
.begin(), 8));
202 r
= m
.equal_range(4);
203 assert(r
.first
== std::next(m
.begin(), 0));
204 assert(r
.second
== std::next(m
.begin(), 0));
205 r
= m
.equal_range(6);
206 assert(r
.first
== std::next(m
.begin(), 1));
207 assert(r
.second
== std::next(m
.begin(), 1));
208 r
= m
.equal_range(8);
209 assert(r
.first
== std::next(m
.begin(), 2));
210 assert(r
.second
== std::next(m
.begin(), 2));
211 r
= m
.equal_range(10);
212 assert(r
.first
== std::next(m
.begin(), 3));
213 assert(r
.second
== std::next(m
.begin(), 3));
214 r
= m
.equal_range(12);
215 assert(r
.first
== std::next(m
.begin(), 4));
216 assert(r
.second
== std::next(m
.begin(), 4));
217 r
= m
.equal_range(14);
218 assert(r
.first
== std::next(m
.begin(), 5));
219 assert(r
.second
== std::next(m
.begin(), 5));
220 r
= m
.equal_range(16);
221 assert(r
.first
== std::next(m
.begin(), 6));
222 assert(r
.second
== std::next(m
.begin(), 6));
223 r
= m
.equal_range(18);
224 assert(r
.first
== std::next(m
.begin(), 7));
225 assert(r
.second
== std::next(m
.begin(), 7));
226 r
= m
.equal_range(20);
227 assert(r
.first
== std::next(m
.begin(), 8));
228 assert(r
.second
== std::next(m
.begin(), 8));
231 #if TEST_STD_VER > 11
234 typedef std::set
<V
, std::less
<>> M
;
236 typedef std::pair
<M::iterator
, M::iterator
> R
;
248 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
249 R r
= m
.equal_range(5);
250 assert(r
.first
== std::next(m
.begin(), 0));
251 assert(r
.second
== std::next(m
.begin(), 1));
252 r
= m
.equal_range(7);
253 assert(r
.first
== std::next(m
.begin(), 1));
254 assert(r
.second
== std::next(m
.begin(), 2));
255 r
= m
.equal_range(9);
256 assert(r
.first
== std::next(m
.begin(), 2));
257 assert(r
.second
== std::next(m
.begin(), 3));
258 r
= m
.equal_range(11);
259 assert(r
.first
== std::next(m
.begin(), 3));
260 assert(r
.second
== std::next(m
.begin(), 4));
261 r
= m
.equal_range(13);
262 assert(r
.first
== std::next(m
.begin(), 4));
263 assert(r
.second
== std::next(m
.begin(), 5));
264 r
= m
.equal_range(15);
265 assert(r
.first
== std::next(m
.begin(), 5));
266 assert(r
.second
== std::next(m
.begin(), 6));
267 r
= m
.equal_range(17);
268 assert(r
.first
== std::next(m
.begin(), 6));
269 assert(r
.second
== std::next(m
.begin(), 7));
270 r
= m
.equal_range(19);
271 assert(r
.first
== std::next(m
.begin(), 7));
272 assert(r
.second
== std::next(m
.begin(), 8));
273 r
= m
.equal_range(4);
274 assert(r
.first
== std::next(m
.begin(), 0));
275 assert(r
.second
== std::next(m
.begin(), 0));
276 r
= m
.equal_range(6);
277 assert(r
.first
== std::next(m
.begin(), 1));
278 assert(r
.second
== std::next(m
.begin(), 1));
279 r
= m
.equal_range(8);
280 assert(r
.first
== std::next(m
.begin(), 2));
281 assert(r
.second
== std::next(m
.begin(), 2));
282 r
= m
.equal_range(10);
283 assert(r
.first
== std::next(m
.begin(), 3));
284 assert(r
.second
== std::next(m
.begin(), 3));
285 r
= m
.equal_range(12);
286 assert(r
.first
== std::next(m
.begin(), 4));
287 assert(r
.second
== std::next(m
.begin(), 4));
288 r
= m
.equal_range(14);
289 assert(r
.first
== std::next(m
.begin(), 5));
290 assert(r
.second
== std::next(m
.begin(), 5));
291 r
= m
.equal_range(16);
292 assert(r
.first
== std::next(m
.begin(), 6));
293 assert(r
.second
== std::next(m
.begin(), 6));
294 r
= m
.equal_range(18);
295 assert(r
.first
== std::next(m
.begin(), 7));
296 assert(r
.second
== std::next(m
.begin(), 7));
297 r
= m
.equal_range(20);
298 assert(r
.first
== std::next(m
.begin(), 8));
299 assert(r
.second
== std::next(m
.begin(), 8));
303 typedef PrivateConstructor V
;
304 typedef std::set
<V
, std::less
<>> M
;
305 typedef std::pair
<M::iterator
, M::iterator
> R
;
308 m
.insert ( V::make ( 5 ));
309 m
.insert ( V::make ( 7 ));
310 m
.insert ( V::make ( 9 ));
311 m
.insert ( V::make ( 11 ));
312 m
.insert ( V::make ( 13 ));
313 m
.insert ( V::make ( 15 ));
314 m
.insert ( V::make ( 17 ));
315 m
.insert ( V::make ( 19 ));
317 R r
= m
.equal_range(5);
318 assert(r
.first
== std::next(m
.begin(), 0));
319 assert(r
.second
== std::next(m
.begin(), 1));
320 r
= m
.equal_range(7);
321 assert(r
.first
== std::next(m
.begin(), 1));
322 assert(r
.second
== std::next(m
.begin(), 2));
323 r
= m
.equal_range(9);
324 assert(r
.first
== std::next(m
.begin(), 2));
325 assert(r
.second
== std::next(m
.begin(), 3));
326 r
= m
.equal_range(11);
327 assert(r
.first
== std::next(m
.begin(), 3));
328 assert(r
.second
== std::next(m
.begin(), 4));
329 r
= m
.equal_range(13);
330 assert(r
.first
== std::next(m
.begin(), 4));
331 assert(r
.second
== std::next(m
.begin(), 5));
332 r
= m
.equal_range(15);
333 assert(r
.first
== std::next(m
.begin(), 5));
334 assert(r
.second
== std::next(m
.begin(), 6));
335 r
= m
.equal_range(17);
336 assert(r
.first
== std::next(m
.begin(), 6));
337 assert(r
.second
== std::next(m
.begin(), 7));
338 r
= m
.equal_range(19);
339 assert(r
.first
== std::next(m
.begin(), 7));
340 assert(r
.second
== std::next(m
.begin(), 8));
341 r
= m
.equal_range(4);
342 assert(r
.first
== std::next(m
.begin(), 0));
343 assert(r
.second
== std::next(m
.begin(), 0));
344 r
= m
.equal_range(6);
345 assert(r
.first
== std::next(m
.begin(), 1));
346 assert(r
.second
== std::next(m
.begin(), 1));
347 r
= m
.equal_range(8);
348 assert(r
.first
== std::next(m
.begin(), 2));
349 assert(r
.second
== std::next(m
.begin(), 2));
350 r
= m
.equal_range(10);
351 assert(r
.first
== std::next(m
.begin(), 3));
352 assert(r
.second
== std::next(m
.begin(), 3));
353 r
= m
.equal_range(12);
354 assert(r
.first
== std::next(m
.begin(), 4));
355 assert(r
.second
== std::next(m
.begin(), 4));
356 r
= m
.equal_range(14);
357 assert(r
.first
== std::next(m
.begin(), 5));
358 assert(r
.second
== std::next(m
.begin(), 5));
359 r
= m
.equal_range(16);
360 assert(r
.first
== std::next(m
.begin(), 6));
361 assert(r
.second
== std::next(m
.begin(), 6));
362 r
= m
.equal_range(18);
363 assert(r
.first
== std::next(m
.begin(), 7));
364 assert(r
.second
== std::next(m
.begin(), 7));
365 r
= m
.equal_range(20);
366 assert(r
.first
== std::next(m
.begin(), 8));
367 assert(r
.second
== std::next(m
.begin(), 8));