1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <set>
11
12 // class set
13
14 // pair<iterator,iterator> equal_range(const key_type& k);
15 // pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
16
17 #include <set>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 #include "private_constructor.hpp"
23
main()24 int main()
25 {
26 {
27 typedef int V;
28 typedef std::set<int> M;
29 {
30 typedef std::pair<M::iterator, M::iterator> R;
31 V ar[] =
32 {
33 5,
34 7,
35 9,
36 11,
37 13,
38 15,
39 17,
40 19
41 };
42 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
43 R r = m.equal_range(5);
44 assert(r.first == next(m.begin(), 0));
45 assert(r.second == next(m.begin(), 1));
46 r = m.equal_range(7);
47 assert(r.first == next(m.begin(), 1));
48 assert(r.second == next(m.begin(), 2));
49 r = m.equal_range(9);
50 assert(r.first == next(m.begin(), 2));
51 assert(r.second == next(m.begin(), 3));
52 r = m.equal_range(11);
53 assert(r.first == next(m.begin(), 3));
54 assert(r.second == next(m.begin(), 4));
55 r = m.equal_range(13);
56 assert(r.first == next(m.begin(), 4));
57 assert(r.second == next(m.begin(), 5));
58 r = m.equal_range(15);
59 assert(r.first == next(m.begin(), 5));
60 assert(r.second == next(m.begin(), 6));
61 r = m.equal_range(17);
62 assert(r.first == next(m.begin(), 6));
63 assert(r.second == next(m.begin(), 7));
64 r = m.equal_range(19);
65 assert(r.first == next(m.begin(), 7));
66 assert(r.second == next(m.begin(), 8));
67 r = m.equal_range(4);
68 assert(r.first == next(m.begin(), 0));
69 assert(r.second == next(m.begin(), 0));
70 r = m.equal_range(6);
71 assert(r.first == next(m.begin(), 1));
72 assert(r.second == next(m.begin(), 1));
73 r = m.equal_range(8);
74 assert(r.first == next(m.begin(), 2));
75 assert(r.second == next(m.begin(), 2));
76 r = m.equal_range(10);
77 assert(r.first == next(m.begin(), 3));
78 assert(r.second == next(m.begin(), 3));
79 r = m.equal_range(12);
80 assert(r.first == next(m.begin(), 4));
81 assert(r.second == next(m.begin(), 4));
82 r = m.equal_range(14);
83 assert(r.first == next(m.begin(), 5));
84 assert(r.second == next(m.begin(), 5));
85 r = m.equal_range(16);
86 assert(r.first == next(m.begin(), 6));
87 assert(r.second == next(m.begin(), 6));
88 r = m.equal_range(18);
89 assert(r.first == next(m.begin(), 7));
90 assert(r.second == next(m.begin(), 7));
91 r = m.equal_range(20);
92 assert(r.first == next(m.begin(), 8));
93 assert(r.second == next(m.begin(), 8));
94 }
95 {
96 typedef std::pair<M::const_iterator, M::const_iterator> R;
97 V ar[] =
98 {
99 5,
100 7,
101 9,
102 11,
103 13,
104 15,
105 17,
106 19
107 };
108 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
109 R r = m.equal_range(5);
110 assert(r.first == next(m.begin(), 0));
111 assert(r.second == next(m.begin(), 1));
112 r = m.equal_range(7);
113 assert(r.first == next(m.begin(), 1));
114 assert(r.second == next(m.begin(), 2));
115 r = m.equal_range(9);
116 assert(r.first == next(m.begin(), 2));
117 assert(r.second == next(m.begin(), 3));
118 r = m.equal_range(11);
119 assert(r.first == next(m.begin(), 3));
120 assert(r.second == next(m.begin(), 4));
121 r = m.equal_range(13);
122 assert(r.first == next(m.begin(), 4));
123 assert(r.second == next(m.begin(), 5));
124 r = m.equal_range(15);
125 assert(r.first == next(m.begin(), 5));
126 assert(r.second == next(m.begin(), 6));
127 r = m.equal_range(17);
128 assert(r.first == next(m.begin(), 6));
129 assert(r.second == next(m.begin(), 7));
130 r = m.equal_range(19);
131 assert(r.first == next(m.begin(), 7));
132 assert(r.second == next(m.begin(), 8));
133 r = m.equal_range(4);
134 assert(r.first == next(m.begin(), 0));
135 assert(r.second == next(m.begin(), 0));
136 r = m.equal_range(6);
137 assert(r.first == next(m.begin(), 1));
138 assert(r.second == next(m.begin(), 1));
139 r = m.equal_range(8);
140 assert(r.first == next(m.begin(), 2));
141 assert(r.second == next(m.begin(), 2));
142 r = m.equal_range(10);
143 assert(r.first == next(m.begin(), 3));
144 assert(r.second == next(m.begin(), 3));
145 r = m.equal_range(12);
146 assert(r.first == next(m.begin(), 4));
147 assert(r.second == next(m.begin(), 4));
148 r = m.equal_range(14);
149 assert(r.first == next(m.begin(), 5));
150 assert(r.second == next(m.begin(), 5));
151 r = m.equal_range(16);
152 assert(r.first == next(m.begin(), 6));
153 assert(r.second == next(m.begin(), 6));
154 r = m.equal_range(18);
155 assert(r.first == next(m.begin(), 7));
156 assert(r.second == next(m.begin(), 7));
157 r = m.equal_range(20);
158 assert(r.first == next(m.begin(), 8));
159 assert(r.second == next(m.begin(), 8));
160 }
161 }
162 #if TEST_STD_VER >= 11
163 {
164 typedef int V;
165 typedef std::set<int, std::less<int>, min_allocator<int>> M;
166 typedef std::pair<M::iterator, M::iterator> R;
167 V ar[] =
168 {
169 5,
170 7,
171 9,
172 11,
173 13,
174 15,
175 17,
176 19
177 };
178 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
179 R r = m.equal_range(5);
180 assert(r.first == next(m.begin(), 0));
181 assert(r.second == next(m.begin(), 1));
182 r = m.equal_range(7);
183 assert(r.first == next(m.begin(), 1));
184 assert(r.second == next(m.begin(), 2));
185 r = m.equal_range(9);
186 assert(r.first == next(m.begin(), 2));
187 assert(r.second == next(m.begin(), 3));
188 r = m.equal_range(11);
189 assert(r.first == next(m.begin(), 3));
190 assert(r.second == next(m.begin(), 4));
191 r = m.equal_range(13);
192 assert(r.first == next(m.begin(), 4));
193 assert(r.second == next(m.begin(), 5));
194 r = m.equal_range(15);
195 assert(r.first == next(m.begin(), 5));
196 assert(r.second == next(m.begin(), 6));
197 r = m.equal_range(17);
198 assert(r.first == next(m.begin(), 6));
199 assert(r.second == next(m.begin(), 7));
200 r = m.equal_range(19);
201 assert(r.first == next(m.begin(), 7));
202 assert(r.second == next(m.begin(), 8));
203 r = m.equal_range(4);
204 assert(r.first == next(m.begin(), 0));
205 assert(r.second == next(m.begin(), 0));
206 r = m.equal_range(6);
207 assert(r.first == next(m.begin(), 1));
208 assert(r.second == next(m.begin(), 1));
209 r = m.equal_range(8);
210 assert(r.first == next(m.begin(), 2));
211 assert(r.second == next(m.begin(), 2));
212 r = m.equal_range(10);
213 assert(r.first == next(m.begin(), 3));
214 assert(r.second == next(m.begin(), 3));
215 r = m.equal_range(12);
216 assert(r.first == next(m.begin(), 4));
217 assert(r.second == next(m.begin(), 4));
218 r = m.equal_range(14);
219 assert(r.first == next(m.begin(), 5));
220 assert(r.second == next(m.begin(), 5));
221 r = m.equal_range(16);
222 assert(r.first == next(m.begin(), 6));
223 assert(r.second == next(m.begin(), 6));
224 r = m.equal_range(18);
225 assert(r.first == next(m.begin(), 7));
226 assert(r.second == next(m.begin(), 7));
227 r = m.equal_range(20);
228 assert(r.first == next(m.begin(), 8));
229 assert(r.second == next(m.begin(), 8));
230 }
231 #endif
232 #if TEST_STD_VER > 11
233 {
234 typedef int V;
235 typedef std::set<V, std::less<>> M;
236 {
237 typedef std::pair<M::iterator, M::iterator> R;
238 V ar[] =
239 {
240 5,
241 7,
242 9,
243 11,
244 13,
245 15,
246 17,
247 19
248 };
249 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
250 R r = m.equal_range(5);
251 assert(r.first == next(m.begin(), 0));
252 assert(r.second == next(m.begin(), 1));
253 r = m.equal_range(7);
254 assert(r.first == next(m.begin(), 1));
255 assert(r.second == next(m.begin(), 2));
256 r = m.equal_range(9);
257 assert(r.first == next(m.begin(), 2));
258 assert(r.second == next(m.begin(), 3));
259 r = m.equal_range(11);
260 assert(r.first == next(m.begin(), 3));
261 assert(r.second == next(m.begin(), 4));
262 r = m.equal_range(13);
263 assert(r.first == next(m.begin(), 4));
264 assert(r.second == next(m.begin(), 5));
265 r = m.equal_range(15);
266 assert(r.first == next(m.begin(), 5));
267 assert(r.second == next(m.begin(), 6));
268 r = m.equal_range(17);
269 assert(r.first == next(m.begin(), 6));
270 assert(r.second == next(m.begin(), 7));
271 r = m.equal_range(19);
272 assert(r.first == next(m.begin(), 7));
273 assert(r.second == next(m.begin(), 8));
274 r = m.equal_range(4);
275 assert(r.first == next(m.begin(), 0));
276 assert(r.second == next(m.begin(), 0));
277 r = m.equal_range(6);
278 assert(r.first == next(m.begin(), 1));
279 assert(r.second == next(m.begin(), 1));
280 r = m.equal_range(8);
281 assert(r.first == next(m.begin(), 2));
282 assert(r.second == next(m.begin(), 2));
283 r = m.equal_range(10);
284 assert(r.first == next(m.begin(), 3));
285 assert(r.second == next(m.begin(), 3));
286 r = m.equal_range(12);
287 assert(r.first == next(m.begin(), 4));
288 assert(r.second == next(m.begin(), 4));
289 r = m.equal_range(14);
290 assert(r.first == next(m.begin(), 5));
291 assert(r.second == next(m.begin(), 5));
292 r = m.equal_range(16);
293 assert(r.first == next(m.begin(), 6));
294 assert(r.second == next(m.begin(), 6));
295 r = m.equal_range(18);
296 assert(r.first == next(m.begin(), 7));
297 assert(r.second == next(m.begin(), 7));
298 r = m.equal_range(20);
299 assert(r.first == next(m.begin(), 8));
300 assert(r.second == next(m.begin(), 8));
301 }
302 }
303 {
304 typedef PrivateConstructor V;
305 typedef std::set<V, std::less<>> M;
306 typedef std::pair<M::iterator, M::iterator> R;
307
308 M m;
309 m.insert ( V::make ( 5 ));
310 m.insert ( V::make ( 7 ));
311 m.insert ( V::make ( 9 ));
312 m.insert ( V::make ( 11 ));
313 m.insert ( V::make ( 13 ));
314 m.insert ( V::make ( 15 ));
315 m.insert ( V::make ( 17 ));
316 m.insert ( V::make ( 19 ));
317
318 R r = m.equal_range(5);
319 assert(r.first == next(m.begin(), 0));
320 assert(r.second == next(m.begin(), 1));
321 r = m.equal_range(7);
322 assert(r.first == next(m.begin(), 1));
323 assert(r.second == next(m.begin(), 2));
324 r = m.equal_range(9);
325 assert(r.first == next(m.begin(), 2));
326 assert(r.second == next(m.begin(), 3));
327 r = m.equal_range(11);
328 assert(r.first == next(m.begin(), 3));
329 assert(r.second == next(m.begin(), 4));
330 r = m.equal_range(13);
331 assert(r.first == next(m.begin(), 4));
332 assert(r.second == next(m.begin(), 5));
333 r = m.equal_range(15);
334 assert(r.first == next(m.begin(), 5));
335 assert(r.second == next(m.begin(), 6));
336 r = m.equal_range(17);
337 assert(r.first == next(m.begin(), 6));
338 assert(r.second == next(m.begin(), 7));
339 r = m.equal_range(19);
340 assert(r.first == next(m.begin(), 7));
341 assert(r.second == next(m.begin(), 8));
342 r = m.equal_range(4);
343 assert(r.first == next(m.begin(), 0));
344 assert(r.second == next(m.begin(), 0));
345 r = m.equal_range(6);
346 assert(r.first == next(m.begin(), 1));
347 assert(r.second == next(m.begin(), 1));
348 r = m.equal_range(8);
349 assert(r.first == next(m.begin(), 2));
350 assert(r.second == next(m.begin(), 2));
351 r = m.equal_range(10);
352 assert(r.first == next(m.begin(), 3));
353 assert(r.second == next(m.begin(), 3));
354 r = m.equal_range(12);
355 assert(r.first == next(m.begin(), 4));
356 assert(r.second == next(m.begin(), 4));
357 r = m.equal_range(14);
358 assert(r.first == next(m.begin(), 5));
359 assert(r.second == next(m.begin(), 5));
360 r = m.equal_range(16);
361 assert(r.first == next(m.begin(), 6));
362 assert(r.second == next(m.begin(), 6));
363 r = m.equal_range(18);
364 assert(r.first == next(m.begin(), 7));
365 assert(r.second == next(m.begin(), 7));
366 r = m.equal_range(20);
367 assert(r.first == next(m.begin(), 8));
368 assert(r.second == next(m.begin(), 8));
369 }
370 #endif
371 }
372