Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libcxx / test / std / containers / associative / map / map.ops / find.pass.cpp
blob4724162c5e35a5718553fb4a21f5ad71d936f789
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 // <map>
11 // class map
13 // iterator find(const key_type& k);
14 // const_iterator find(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**)
27 typedef std::pair<const int, double> V;
28 typedef std::map<int, double> M;
30 typedef M::iterator R;
31 V ar[] =
33 V(5, 5),
34 V(6, 6),
35 V(7, 7),
36 V(8, 8),
37 V(9, 9),
38 V(10, 10),
39 V(11, 11),
40 V(12, 12)
42 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
43 R r = m.find(5);
44 assert(r == m.begin());
45 r = m.find(6);
46 assert(r == std::next(m.begin()));
47 r = m.find(7);
48 assert(r == std::next(m.begin(), 2));
49 r = m.find(8);
50 assert(r == std::next(m.begin(), 3));
51 r = m.find(9);
52 assert(r == std::next(m.begin(), 4));
53 r = m.find(10);
54 assert(r == std::next(m.begin(), 5));
55 r = m.find(11);
56 assert(r == std::next(m.begin(), 6));
57 r = m.find(12);
58 assert(r == std::next(m.begin(), 7));
59 r = m.find(4);
60 assert(r == std::next(m.begin(), 8));
63 typedef M::const_iterator R;
64 V ar[] =
66 V(5, 5),
67 V(6, 6),
68 V(7, 7),
69 V(8, 8),
70 V(9, 9),
71 V(10, 10),
72 V(11, 11),
73 V(12, 12)
75 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
76 R r = m.find(5);
77 assert(r == m.begin());
78 r = m.find(6);
79 assert(r == std::next(m.begin()));
80 r = m.find(7);
81 assert(r == std::next(m.begin(), 2));
82 r = m.find(8);
83 assert(r == std::next(m.begin(), 3));
84 r = m.find(9);
85 assert(r == std::next(m.begin(), 4));
86 r = m.find(10);
87 assert(r == std::next(m.begin(), 5));
88 r = m.find(11);
89 assert(r == std::next(m.begin(), 6));
90 r = m.find(12);
91 assert(r == std::next(m.begin(), 7));
92 r = m.find(4);
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;
102 V ar[] =
104 V(5, 5),
105 V(6, 6),
106 V(7, 7),
107 V(8, 8),
108 V(9, 9),
109 V(10, 10),
110 V(11, 11),
111 V(12, 12)
113 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
114 R r = m.find(5);
115 assert(r == m.begin());
116 r = m.find(6);
117 assert(r == std::next(m.begin()));
118 r = m.find(7);
119 assert(r == std::next(m.begin(), 2));
120 r = m.find(8);
121 assert(r == std::next(m.begin(), 3));
122 r = m.find(9);
123 assert(r == std::next(m.begin(), 4));
124 r = m.find(10);
125 assert(r == std::next(m.begin(), 5));
126 r = m.find(11);
127 assert(r == std::next(m.begin(), 6));
128 r = m.find(12);
129 assert(r == std::next(m.begin(), 7));
130 r = m.find(4);
131 assert(r == std::next(m.begin(), 8));
134 typedef M::const_iterator R;
135 V ar[] =
137 V(5, 5),
138 V(6, 6),
139 V(7, 7),
140 V(8, 8),
141 V(9, 9),
142 V(10, 10),
143 V(11, 11),
144 V(12, 12)
146 const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
147 R r = m.find(5);
148 assert(r == m.begin());
149 r = m.find(6);
150 assert(r == std::next(m.begin()));
151 r = m.find(7);
152 assert(r == std::next(m.begin(), 2));
153 r = m.find(8);
154 assert(r == std::next(m.begin(), 3));
155 r = m.find(9);
156 assert(r == std::next(m.begin(), 4));
157 r = m.find(10);
158 assert(r == std::next(m.begin(), 5));
159 r = m.find(11);
160 assert(r == std::next(m.begin(), 6));
161 r = m.find(12);
162 assert(r == std::next(m.begin(), 7));
163 r = m.find(4);
164 assert(r == std::next(m.begin(), 8));
167 #endif
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;
174 V ar[] =
176 V(5, 5),
177 V(6, 6),
178 V(7, 7),
179 V(8, 8),
180 V(9, 9),
181 V(10, 10),
182 V(11, 11),
183 V(12, 12)
185 M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
186 R r = m.find(5);
187 assert(r == m.begin());
188 r = m.find(6);
189 assert(r == std::next(m.begin()));
190 r = m.find(7);
191 assert(r == std::next(m.begin(), 2));
192 r = m.find(8);
193 assert(r == std::next(m.begin(), 3));
194 r = m.find(9);
195 assert(r == std::next(m.begin(), 4));
196 r = m.find(10);
197 assert(r == std::next(m.begin(), 5));
198 r = m.find(11);
199 assert(r == std::next(m.begin(), 6));
200 r = m.find(12);
201 assert(r == std::next(m.begin(), 7));
202 r = m.find(4);
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;
230 M m;
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;
240 R r = m.find(5);
241 assert(r == m.begin());
242 r = m.find(6);
243 assert(r == std::next(m.begin()));
244 r = m.find(7);
245 assert(r == std::next(m.begin(), 2));
246 r = m.find(8);
247 assert(r == std::next(m.begin(), 3));
248 r = m.find(9);
249 assert(r == std::next(m.begin(), 4));
250 r = m.find(10);
251 assert(r == std::next(m.begin(), 5));
252 r = m.find(11);
253 assert(r == std::next(m.begin(), 6));
254 r = m.find(12);
255 assert(r == std::next(m.begin(), 7));
256 r = m.find(4);
257 assert(r == std::next(m.begin(), 8));
259 #endif
261 return 0;