[SandboxVec][Scheduler] Forbid crossing BBs (#124369)
[llvm-project.git] / libcxx / test / std / containers / associative / multimap / multimap.ops / equal_range.pass.cpp
blobc134c779a40c76f10fc57a1e64f576e179c7a0a0
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 //===----------------------------------------------------------------------===//
9 // <multimap>
11 // class multimap
13 // pair<iterator, iterator> equal_range(const key_type& k);
14 // pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
16 #include <map>
17 #include <cassert>
19 #include "test_macros.h"
20 #include "min_allocator.h"
21 #include "private_constructor.h"
22 #include "is_transparent.h"
24 int main(int, char**)
26 typedef std::pair<const int, double> V;
28 typedef std::multimap<int, double> M;
30 typedef std::pair<M::iterator, M::iterator> R;
31 V ar[] =
33 V(5, 1),
34 V(5, 2),
35 V(5, 3),
36 V(7, 1),
37 V(7, 2),
38 V(7, 3),
39 V(9, 1),
40 V(9, 2),
41 V(9, 3)
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());
47 r = m.equal_range(5);
48 assert(r.first == m.begin());
49 assert(r.second == std::next(m.begin(), 3));
50 r = m.equal_range(6);
51 assert(r.first == std::next(m.begin(), 3));
52 assert(r.second == std::next(m.begin(), 3));
53 r = m.equal_range(7);
54 assert(r.first == std::next(m.begin(), 3));
55 assert(r.second == std::next(m.begin(), 6));
56 r = m.equal_range(8);
57 assert(r.first == std::next(m.begin(), 6));
58 assert(r.second == std::next(m.begin(), 6));
59 r = m.equal_range(9);
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;
68 V ar[] =
70 V(5, 1),
71 V(5, 2),
72 V(5, 3),
73 V(7, 1),
74 V(7, 2),
75 V(7, 3),
76 V(9, 1),
77 V(9, 2),
78 V(9, 3)
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());
84 r = m.equal_range(5);
85 assert(r.first == m.begin());
86 assert(r.second == std::next(m.begin(), 3));
87 r = m.equal_range(6);
88 assert(r.first == std::next(m.begin(), 3));
89 assert(r.second == std::next(m.begin(), 3));
90 r = m.equal_range(7);
91 assert(r.first == std::next(m.begin(), 3));
92 assert(r.second == std::next(m.begin(), 6));
93 r = m.equal_range(8);
94 assert(r.first == std::next(m.begin(), 6));
95 assert(r.second == std::next(m.begin(), 6));
96 r = m.equal_range(9);
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;
109 V ar[] =
111 V(5, 1),
112 V(5, 2),
113 V(5, 3),
114 V(7, 1),
115 V(7, 2),
116 V(7, 3),
117 V(9, 1),
118 V(9, 2),
119 V(9, 3)
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;
146 V ar[] =
148 V(5, 1),
149 V(5, 2),
150 V(5, 3),
151 V(7, 1),
152 V(7, 2),
153 V(7, 3),
154 V(9, 1),
155 V(9, 2),
156 V(9, 3)
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());
182 #endif
183 #if TEST_STD_VER > 11
185 typedef std::multimap<int, double, std::less<>> M;
187 typedef std::pair<M::iterator, M::iterator> R;
188 V ar[] =
190 V(5, 1),
191 V(5, 2),
192 V(5, 3),
193 V(7, 1),
194 V(7, 2),
195 V(7, 3),
196 V(9, 1),
197 V(9, 2),
198 V(9, 3)
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;
251 M m;
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());
285 #endif
287 return 0;