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 // iterator find(const key_type& k);
14 // const_iterator find(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"
27 typedef std::pair
<const int, double> V
;
28 typedef std::map
<int, double> M
;
30 typedef M::iterator R
;
42 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
44 assert(r
== m
.begin());
46 assert(r
== std::next(m
.begin()));
48 assert(r
== std::next(m
.begin(), 2));
50 assert(r
== std::next(m
.begin(), 3));
52 assert(r
== std::next(m
.begin(), 4));
54 assert(r
== std::next(m
.begin(), 5));
56 assert(r
== std::next(m
.begin(), 6));
58 assert(r
== std::next(m
.begin(), 7));
60 assert(r
== std::next(m
.begin(), 8));
63 typedef M::const_iterator R
;
75 const M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
77 assert(r
== m
.begin());
79 assert(r
== std::next(m
.begin()));
81 assert(r
== std::next(m
.begin(), 2));
83 assert(r
== std::next(m
.begin(), 3));
85 assert(r
== std::next(m
.begin(), 4));
87 assert(r
== std::next(m
.begin(), 5));
89 assert(r
== std::next(m
.begin(), 6));
91 assert(r
== std::next(m
.begin(), 7));
93 assert(r
== std::next(m
.begin(), 8));
96 #if TEST_STD_VER >= 11
98 typedef std::pair
<const int, double> V
;
99 typedef std::map
<int, double, std::less
<int>, min_allocator
<V
>> M
;
101 typedef M::iterator R
;
113 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
115 assert(r
== m
.begin());
117 assert(r
== std::next(m
.begin()));
119 assert(r
== std::next(m
.begin(), 2));
121 assert(r
== std::next(m
.begin(), 3));
123 assert(r
== std::next(m
.begin(), 4));
125 assert(r
== std::next(m
.begin(), 5));
127 assert(r
== std::next(m
.begin(), 6));
129 assert(r
== std::next(m
.begin(), 7));
131 assert(r
== std::next(m
.begin(), 8));
134 typedef M::const_iterator R
;
146 const M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
148 assert(r
== m
.begin());
150 assert(r
== std::next(m
.begin()));
152 assert(r
== std::next(m
.begin(), 2));
154 assert(r
== std::next(m
.begin(), 3));
156 assert(r
== std::next(m
.begin(), 4));
158 assert(r
== std::next(m
.begin(), 5));
160 assert(r
== std::next(m
.begin(), 6));
162 assert(r
== std::next(m
.begin(), 7));
164 assert(r
== std::next(m
.begin(), 8));
168 #if TEST_STD_VER > 11
170 typedef std::pair
<const int, double> V
;
171 typedef std::map
<int, double, std::less
<>> M
;
172 typedef M::iterator R
;
185 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
187 assert(r
== m
.begin());
189 assert(r
== std::next(m
.begin()));
191 assert(r
== std::next(m
.begin(), 2));
193 assert(r
== std::next(m
.begin(), 3));
195 assert(r
== std::next(m
.begin(), 4));
197 assert(r
== std::next(m
.begin(), 5));
199 assert(r
== std::next(m
.begin(), 6));
201 assert(r
== std::next(m
.begin(), 7));
203 assert(r
== std::next(m
.begin(), 8));
205 r
= m
.find(C2Int(5));
206 assert(r
== m
.begin());
207 r
= m
.find(C2Int(6));
208 assert(r
== std::next(m
.begin()));
209 r
= m
.find(C2Int(7));
210 assert(r
== std::next(m
.begin(), 2));
211 r
= m
.find(C2Int(8));
212 assert(r
== std::next(m
.begin(), 3));
213 r
= m
.find(C2Int(9));
214 assert(r
== std::next(m
.begin(), 4));
215 r
= m
.find(C2Int(10));
216 assert(r
== std::next(m
.begin(), 5));
217 r
= m
.find(C2Int(11));
218 assert(r
== std::next(m
.begin(), 6));
219 r
= m
.find(C2Int(12));
220 assert(r
== std::next(m
.begin(), 7));
221 r
= m
.find(C2Int(4));
222 assert(r
== std::next(m
.begin(), 8));
226 typedef PrivateConstructor PC
;
227 typedef std::map
<PC
, double, std::less
<>> M
;
228 typedef M::iterator R
;
231 m
[ PC::make(5) ] = 5;
232 m
[ PC::make(6) ] = 6;
233 m
[ PC::make(7) ] = 7;
234 m
[ PC::make(8) ] = 8;
235 m
[ PC::make(9) ] = 9;
236 m
[ PC::make(10) ] = 10;
237 m
[ PC::make(11) ] = 11;
238 m
[ PC::make(12) ] = 12;
241 assert(r
== m
.begin());
243 assert(r
== std::next(m
.begin()));
245 assert(r
== std::next(m
.begin(), 2));
247 assert(r
== std::next(m
.begin(), 3));
249 assert(r
== std::next(m
.begin(), 4));
251 assert(r
== std::next(m
.begin(), 5));
253 assert(r
== std::next(m
.begin(), 6));
255 assert(r
== std::next(m
.begin(), 7));
257 assert(r
== std::next(m
.begin(), 8));