llvm-project
265 строк · 8.2 Кб
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// <set>
10
11// class multiset
12
13// pair<iterator,iterator> equal_range(const key_type& k);
14// pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
15
16#include <set>
17#include <cassert>
18
19#include "test_macros.h"
20#include "min_allocator.h"
21#include "private_constructor.h"
22
23int main(int, char**)
24{
25{
26typedef int V;
27typedef std::multiset<int> M;
28{
29typedef std::pair<M::iterator, M::iterator> R;
30V ar[] =
31{
325,
335,
345,
357,
367,
377,
389,
399,
409
41};
42M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
43R r = m.equal_range(4);
44assert(r.first == std::next(m.begin(), 0));
45assert(r.second == std::next(m.begin(), 0));
46r = m.equal_range(5);
47assert(r.first == std::next(m.begin(), 0));
48assert(r.second == std::next(m.begin(), 3));
49r = m.equal_range(6);
50assert(r.first == std::next(m.begin(), 3));
51assert(r.second == std::next(m.begin(), 3));
52r = m.equal_range(7);
53assert(r.first == std::next(m.begin(), 3));
54assert(r.second == std::next(m.begin(), 6));
55r = m.equal_range(8);
56assert(r.first == std::next(m.begin(), 6));
57assert(r.second == std::next(m.begin(), 6));
58r = m.equal_range(9);
59assert(r.first == std::next(m.begin(), 6));
60assert(r.second == std::next(m.begin(), 9));
61r = m.equal_range(10);
62assert(r.first == std::next(m.begin(), 9));
63assert(r.second == std::next(m.begin(), 9));
64}
65{
66typedef std::pair<M::const_iterator, M::const_iterator> R;
67V ar[] =
68{
695,
705,
715,
727,
737,
747,
759,
769,
779
78};
79const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
80R r = m.equal_range(4);
81assert(r.first == std::next(m.begin(), 0));
82assert(r.second == std::next(m.begin(), 0));
83r = m.equal_range(5);
84assert(r.first == std::next(m.begin(), 0));
85assert(r.second == std::next(m.begin(), 3));
86r = m.equal_range(6);
87assert(r.first == std::next(m.begin(), 3));
88assert(r.second == std::next(m.begin(), 3));
89r = m.equal_range(7);
90assert(r.first == std::next(m.begin(), 3));
91assert(r.second == std::next(m.begin(), 6));
92r = m.equal_range(8);
93assert(r.first == std::next(m.begin(), 6));
94assert(r.second == std::next(m.begin(), 6));
95r = m.equal_range(9);
96assert(r.first == std::next(m.begin(), 6));
97assert(r.second == std::next(m.begin(), 9));
98r = m.equal_range(10);
99assert(r.first == std::next(m.begin(), 9));
100assert(r.second == std::next(m.begin(), 9));
101}
102}
103#if TEST_STD_VER >= 11
104{
105typedef int V;
106typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
107{
108typedef std::pair<M::iterator, M::iterator> R;
109V ar[] =
110{
1115,
1125,
1135,
1147,
1157,
1167,
1179,
1189,
1199
120};
121M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
122R r = m.equal_range(4);
123assert(r.first == std::next(m.begin(), 0));
124assert(r.second == std::next(m.begin(), 0));
125r = m.equal_range(5);
126assert(r.first == std::next(m.begin(), 0));
127assert(r.second == std::next(m.begin(), 3));
128r = m.equal_range(6);
129assert(r.first == std::next(m.begin(), 3));
130assert(r.second == std::next(m.begin(), 3));
131r = m.equal_range(7);
132assert(r.first == std::next(m.begin(), 3));
133assert(r.second == std::next(m.begin(), 6));
134r = m.equal_range(8);
135assert(r.first == std::next(m.begin(), 6));
136assert(r.second == std::next(m.begin(), 6));
137r = m.equal_range(9);
138assert(r.first == std::next(m.begin(), 6));
139assert(r.second == std::next(m.begin(), 9));
140r = m.equal_range(10);
141assert(r.first == std::next(m.begin(), 9));
142assert(r.second == std::next(m.begin(), 9));
143}
144{
145typedef std::pair<M::const_iterator, M::const_iterator> R;
146V ar[] =
147{
1485,
1495,
1505,
1517,
1527,
1537,
1549,
1559,
1569
157};
158const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
159R r = m.equal_range(4);
160assert(r.first == std::next(m.begin(), 0));
161assert(r.second == std::next(m.begin(), 0));
162r = m.equal_range(5);
163assert(r.first == std::next(m.begin(), 0));
164assert(r.second == std::next(m.begin(), 3));
165r = m.equal_range(6);
166assert(r.first == std::next(m.begin(), 3));
167assert(r.second == std::next(m.begin(), 3));
168r = m.equal_range(7);
169assert(r.first == std::next(m.begin(), 3));
170assert(r.second == std::next(m.begin(), 6));
171r = m.equal_range(8);
172assert(r.first == std::next(m.begin(), 6));
173assert(r.second == std::next(m.begin(), 6));
174r = m.equal_range(9);
175assert(r.first == std::next(m.begin(), 6));
176assert(r.second == std::next(m.begin(), 9));
177r = m.equal_range(10);
178assert(r.first == std::next(m.begin(), 9));
179assert(r.second == std::next(m.begin(), 9));
180}
181}
182#endif
183#if TEST_STD_VER > 11
184{
185typedef int V;
186typedef std::multiset<V, std::less<>> M;
187typedef std::pair<M::iterator, M::iterator> R;
188V ar[] =
189{
1905,
1915,
1925,
1937,
1947,
1957,
1969,
1979,
1989
199};
200M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
201R r = m.equal_range(4);
202assert(r.first == std::next(m.begin(), 0));
203assert(r.second == std::next(m.begin(), 0));
204r = m.equal_range(5);
205assert(r.first == std::next(m.begin(), 0));
206assert(r.second == std::next(m.begin(), 3));
207r = m.equal_range(6);
208assert(r.first == std::next(m.begin(), 3));
209assert(r.second == std::next(m.begin(), 3));
210r = m.equal_range(7);
211assert(r.first == std::next(m.begin(), 3));
212assert(r.second == std::next(m.begin(), 6));
213r = m.equal_range(8);
214assert(r.first == std::next(m.begin(), 6));
215assert(r.second == std::next(m.begin(), 6));
216r = m.equal_range(9);
217assert(r.first == std::next(m.begin(), 6));
218assert(r.second == std::next(m.begin(), 9));
219r = m.equal_range(10);
220assert(r.first == std::next(m.begin(), 9));
221assert(r.second == std::next(m.begin(), 9));
222}
223
224{
225typedef PrivateConstructor V;
226typedef std::multiset<V, std::less<>> M;
227typedef std::pair<M::iterator, M::iterator> R;
228
229M m;
230m.insert ( V::make ( 5 ));
231m.insert ( V::make ( 5 ));
232m.insert ( V::make ( 5 ));
233m.insert ( V::make ( 7 ));
234m.insert ( V::make ( 7 ));
235m.insert ( V::make ( 7 ));
236m.insert ( V::make ( 9 ));
237m.insert ( V::make ( 9 ));
238m.insert ( V::make ( 9 ));
239
240R r = m.equal_range(4);
241assert(r.first == std::next(m.begin(), 0));
242assert(r.second == std::next(m.begin(), 0));
243r = m.equal_range(5);
244assert(r.first == std::next(m.begin(), 0));
245assert(r.second == std::next(m.begin(), 3));
246r = m.equal_range(6);
247assert(r.first == std::next(m.begin(), 3));
248assert(r.second == std::next(m.begin(), 3));
249r = m.equal_range(7);
250assert(r.first == std::next(m.begin(), 3));
251assert(r.second == std::next(m.begin(), 6));
252r = m.equal_range(8);
253assert(r.first == std::next(m.begin(), 6));
254assert(r.second == std::next(m.begin(), 6));
255r = m.equal_range(9);
256assert(r.first == std::next(m.begin(), 6));
257assert(r.second == std::next(m.begin(), 9));
258r = m.equal_range(10);
259assert(r.first == std::next(m.begin(), 9));
260assert(r.second == std::next(m.begin(), 9));
261}
262#endif
263
264return 0;
265}
266