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"
22 #include "is_transparent.h"
26 typedef std::pair
<const int, double> V
;
28 typedef std::multimap
<int, double> M
;
30 typedef std::pair
<M::iterator
, M::iterator
> R
;
43 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
44 R r
= m
.equal_range(4);
45 assert(r
.first
== m
.begin());
46 assert(r
.second
== m
.begin());
48 assert(r
.first
== m
.begin());
49 assert(r
.second
== std::next(m
.begin(), 3));
51 assert(r
.first
== std::next(m
.begin(), 3));
52 assert(r
.second
== std::next(m
.begin(), 3));
54 assert(r
.first
== std::next(m
.begin(), 3));
55 assert(r
.second
== std::next(m
.begin(), 6));
57 assert(r
.first
== std::next(m
.begin(), 6));
58 assert(r
.second
== std::next(m
.begin(), 6));
60 assert(r
.first
== std::next(m
.begin(), 6));
61 assert(r
.second
== std::next(m
.begin(), 9));
62 r
= m
.equal_range(10);
63 assert(r
.first
== m
.end());
64 assert(r
.second
== m
.end());
67 typedef std::pair
<M::const_iterator
, M::const_iterator
> R
;
80 const M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
81 R r
= m
.equal_range(4);
82 assert(r
.first
== m
.begin());
83 assert(r
.second
== m
.begin());
85 assert(r
.first
== m
.begin());
86 assert(r
.second
== std::next(m
.begin(), 3));
88 assert(r
.first
== std::next(m
.begin(), 3));
89 assert(r
.second
== std::next(m
.begin(), 3));
91 assert(r
.first
== std::next(m
.begin(), 3));
92 assert(r
.second
== std::next(m
.begin(), 6));
94 assert(r
.first
== std::next(m
.begin(), 6));
95 assert(r
.second
== std::next(m
.begin(), 6));
97 assert(r
.first
== std::next(m
.begin(), 6));
98 assert(r
.second
== std::next(m
.begin(), 9));
99 r
= m
.equal_range(10);
100 assert(r
.first
== m
.end());
101 assert(r
.second
== m
.end());
104 #if TEST_STD_VER >= 11
106 typedef std::multimap
<int, double, std::less
<int>, min_allocator
<std::pair
<const int, double>>> M
;
108 typedef std::pair
<M::iterator
, M::iterator
> R
;
121 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
122 R r
= m
.equal_range(4);
123 assert(r
.first
== m
.begin());
124 assert(r
.second
== m
.begin());
125 r
= m
.equal_range(5);
126 assert(r
.first
== m
.begin());
127 assert(r
.second
== std::next(m
.begin(), 3));
128 r
= m
.equal_range(6);
129 assert(r
.first
== std::next(m
.begin(), 3));
130 assert(r
.second
== std::next(m
.begin(), 3));
131 r
= m
.equal_range(7);
132 assert(r
.first
== std::next(m
.begin(), 3));
133 assert(r
.second
== std::next(m
.begin(), 6));
134 r
= m
.equal_range(8);
135 assert(r
.first
== std::next(m
.begin(), 6));
136 assert(r
.second
== std::next(m
.begin(), 6));
137 r
= m
.equal_range(9);
138 assert(r
.first
== std::next(m
.begin(), 6));
139 assert(r
.second
== std::next(m
.begin(), 9));
140 r
= m
.equal_range(10);
141 assert(r
.first
== m
.end());
142 assert(r
.second
== m
.end());
145 typedef std::pair
<M::const_iterator
, M::const_iterator
> R
;
158 const M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
159 R r
= m
.equal_range(4);
160 assert(r
.first
== m
.begin());
161 assert(r
.second
== m
.begin());
162 r
= m
.equal_range(5);
163 assert(r
.first
== m
.begin());
164 assert(r
.second
== std::next(m
.begin(), 3));
165 r
= m
.equal_range(6);
166 assert(r
.first
== std::next(m
.begin(), 3));
167 assert(r
.second
== std::next(m
.begin(), 3));
168 r
= m
.equal_range(7);
169 assert(r
.first
== std::next(m
.begin(), 3));
170 assert(r
.second
== std::next(m
.begin(), 6));
171 r
= m
.equal_range(8);
172 assert(r
.first
== std::next(m
.begin(), 6));
173 assert(r
.second
== std::next(m
.begin(), 6));
174 r
= m
.equal_range(9);
175 assert(r
.first
== std::next(m
.begin(), 6));
176 assert(r
.second
== std::next(m
.begin(), 9));
177 r
= m
.equal_range(10);
178 assert(r
.first
== m
.end());
179 assert(r
.second
== m
.end());
183 #if TEST_STD_VER > 11
185 typedef std::multimap
<int, double, std::less
<>> M
;
187 typedef std::pair
<M::iterator
, M::iterator
> R
;
200 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
201 R r
= m
.equal_range(4);
202 assert(r
.first
== m
.begin());
203 assert(r
.second
== m
.begin());
204 r
= m
.equal_range(5);
205 assert(r
.first
== m
.begin());
206 assert(r
.second
== std::next(m
.begin(), 3));
207 r
= m
.equal_range(6);
208 assert(r
.first
== std::next(m
.begin(), 3));
209 assert(r
.second
== std::next(m
.begin(), 3));
210 r
= m
.equal_range(7);
211 assert(r
.first
== std::next(m
.begin(), 3));
212 assert(r
.second
== std::next(m
.begin(), 6));
213 r
= m
.equal_range(8);
214 assert(r
.first
== std::next(m
.begin(), 6));
215 assert(r
.second
== std::next(m
.begin(), 6));
216 r
= m
.equal_range(9);
217 assert(r
.first
== std::next(m
.begin(), 6));
218 assert(r
.second
== std::next(m
.begin(), 9));
219 r
= m
.equal_range(10);
220 assert(r
.first
== m
.end());
221 assert(r
.second
== m
.end());
223 r
= m
.equal_range(C2Int(4));
224 assert(r
.first
== m
.begin());
225 assert(r
.second
== m
.begin());
226 r
= m
.equal_range(C2Int(5));
227 assert(r
.first
== m
.begin());
228 assert(r
.second
== std::next(m
.begin(), 3));
229 r
= m
.equal_range(C2Int(6));
230 assert(r
.first
== std::next(m
.begin(), 3));
231 assert(r
.second
== std::next(m
.begin(), 3));
232 r
= m
.equal_range(C2Int(7));
233 assert(r
.first
== std::next(m
.begin(), 3));
234 assert(r
.second
== std::next(m
.begin(), 6));
235 r
= m
.equal_range(C2Int(8));
236 assert(r
.first
== std::next(m
.begin(), 6));
237 assert(r
.second
== std::next(m
.begin(), 6));
238 r
= m
.equal_range(C2Int(9));
239 assert(r
.first
== std::next(m
.begin(), 6));
240 assert(r
.second
== std::next(m
.begin(), 9));
241 r
= m
.equal_range(C2Int(10));
242 assert(r
.first
== m
.end());
243 assert(r
.second
== m
.end());
247 typedef PrivateConstructor PC
;
248 typedef std::multimap
<PC
, double, std::less
<>> M
;
249 typedef std::pair
<M::iterator
, M::iterator
> R
;
252 m
.insert ( std::make_pair
<PC
, double> ( PC::make(5), 1 ));
253 m
.insert ( std::make_pair
<PC
, double> ( PC::make(5), 2 ));
254 m
.insert ( std::make_pair
<PC
, double> ( PC::make(5), 3 ));
255 m
.insert ( std::make_pair
<PC
, double> ( PC::make(7), 1 ));
256 m
.insert ( std::make_pair
<PC
, double> ( PC::make(7), 2 ));
257 m
.insert ( std::make_pair
<PC
, double> ( PC::make(7), 3 ));
258 m
.insert ( std::make_pair
<PC
, double> ( PC::make(9), 1 ));
259 m
.insert ( std::make_pair
<PC
, double> ( PC::make(9), 2 ));
260 m
.insert ( std::make_pair
<PC
, double> ( PC::make(9), 3 ));
262 // assert(m.size() == 9);
263 R r
= m
.equal_range(4);
264 assert(r
.first
== m
.begin());
265 assert(r
.second
== m
.begin());
266 r
= m
.equal_range(5);
267 assert(r
.first
== m
.begin());
268 assert(r
.second
== std::next(m
.begin(), 3));
269 r
= m
.equal_range(6);
270 assert(r
.first
== std::next(m
.begin(), 3));
271 assert(r
.second
== std::next(m
.begin(), 3));
272 r
= m
.equal_range(7);
273 assert(r
.first
== std::next(m
.begin(), 3));
274 assert(r
.second
== std::next(m
.begin(), 6));
275 r
= m
.equal_range(8);
276 assert(r
.first
== std::next(m
.begin(), 6));
277 assert(r
.second
== std::next(m
.begin(), 6));
278 r
= m
.equal_range(9);
279 assert(r
.first
== std::next(m
.begin(), 6));
280 assert(r
.second
== std::next(m
.begin(), 9));
281 r
= m
.equal_range(10);
282 assert(r
.first
== m
.end());
283 assert(r
.second
== m
.end());