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 | // <map> |
10 | |
11 | // class multimap |
12 | |
13 | // iterator find(const key_type& k); |
14 | // const_iterator find(const key_type& k) const; |
15 | |
16 | #include <map> |
17 | #include <cassert> |
18 | |
19 | #include "test_macros.h" |
20 | #include "min_allocator.h" |
21 | #include "private_constructor.h" |
22 | #include "is_transparent.h" |
23 | |
24 | int main(int, char**) |
25 | { |
26 | typedef std::pair<const int, double> V; |
27 | { |
28 | typedef std::multimap<int, double> M; |
29 | { |
30 | typedef M::iterator R; |
31 | V ar[] = |
32 | { |
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) |
42 | }; |
43 | M m(ar, ar+sizeof(ar)/sizeof(ar[0])); |
44 | R r = m.find(x: 5); |
45 | assert(r == m.begin()); |
46 | r = m.find(x: 6); |
47 | assert(r == m.end()); |
48 | r = m.find(x: 7); |
49 | assert(r == std::next(m.begin(), 3)); |
50 | r = m.find(x: 8); |
51 | assert(r == m.end()); |
52 | r = m.find(x: 9); |
53 | assert(r == std::next(m.begin(), 6)); |
54 | r = m.find(x: 10); |
55 | assert(r == m.end()); |
56 | } |
57 | { |
58 | typedef M::const_iterator R; |
59 | V ar[] = |
60 | { |
61 | V(5, 1), |
62 | V(5, 2), |
63 | V(5, 3), |
64 | V(7, 1), |
65 | V(7, 2), |
66 | V(7, 3), |
67 | V(9, 1), |
68 | V(9, 2), |
69 | V(9, 3) |
70 | }; |
71 | const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); |
72 | R r = m.find(x: 5); |
73 | assert(r == m.begin()); |
74 | r = m.find(x: 6); |
75 | assert(r == m.end()); |
76 | r = m.find(x: 7); |
77 | assert(r == std::next(m.begin(), 3)); |
78 | r = m.find(x: 8); |
79 | assert(r == m.end()); |
80 | r = m.find(x: 9); |
81 | assert(r == std::next(m.begin(), 6)); |
82 | r = m.find(x: 10); |
83 | assert(r == m.end()); |
84 | } |
85 | } |
86 | #if TEST_STD_VER >= 11 |
87 | { |
88 | typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; |
89 | { |
90 | typedef M::iterator R; |
91 | V ar[] = |
92 | { |
93 | V(5, 1), |
94 | V(5, 2), |
95 | V(5, 3), |
96 | V(7, 1), |
97 | V(7, 2), |
98 | V(7, 3), |
99 | V(9, 1), |
100 | V(9, 2), |
101 | V(9, 3) |
102 | }; |
103 | M m(ar, ar+sizeof(ar)/sizeof(ar[0])); |
104 | R r = m.find(5); |
105 | assert(r == m.begin()); |
106 | r = m.find(6); |
107 | assert(r == m.end()); |
108 | r = m.find(7); |
109 | assert(r == std::next(m.begin(), 3)); |
110 | r = m.find(8); |
111 | assert(r == m.end()); |
112 | r = m.find(9); |
113 | assert(r == std::next(m.begin(), 6)); |
114 | r = m.find(10); |
115 | assert(r == m.end()); |
116 | } |
117 | { |
118 | typedef M::const_iterator R; |
119 | V ar[] = |
120 | { |
121 | V(5, 1), |
122 | V(5, 2), |
123 | V(5, 3), |
124 | V(7, 1), |
125 | V(7, 2), |
126 | V(7, 3), |
127 | V(9, 1), |
128 | V(9, 2), |
129 | V(9, 3) |
130 | }; |
131 | const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); |
132 | R r = m.find(5); |
133 | assert(r == m.begin()); |
134 | r = m.find(6); |
135 | assert(r == m.end()); |
136 | r = m.find(7); |
137 | assert(r == std::next(m.begin(), 3)); |
138 | r = m.find(8); |
139 | assert(r == m.end()); |
140 | r = m.find(9); |
141 | assert(r == std::next(m.begin(), 6)); |
142 | r = m.find(10); |
143 | assert(r == m.end()); |
144 | } |
145 | } |
146 | #endif |
147 | #if TEST_STD_VER > 11 |
148 | { |
149 | typedef std::multimap<int, double, std::less<>> M; |
150 | typedef M::iterator R; |
151 | |
152 | V ar[] = |
153 | { |
154 | V(5, 1), |
155 | V(5, 2), |
156 | V(5, 3), |
157 | V(7, 1), |
158 | V(7, 2), |
159 | V(7, 3), |
160 | V(9, 1), |
161 | V(9, 2), |
162 | V(9, 3) |
163 | }; |
164 | M m(ar, ar+sizeof(ar)/sizeof(ar[0])); |
165 | R r = m.find(5); |
166 | assert(r == m.begin()); |
167 | r = m.find(6); |
168 | assert(r == m.end()); |
169 | r = m.find(7); |
170 | assert(r == std::next(m.begin(), 3)); |
171 | r = m.find(8); |
172 | assert(r == m.end()); |
173 | r = m.find(9); |
174 | assert(r == std::next(m.begin(), 6)); |
175 | r = m.find(10); |
176 | assert(r == m.end()); |
177 | |
178 | r = m.find(C2Int(5)); |
179 | assert(r == m.begin()); |
180 | r = m.find(C2Int(6)); |
181 | assert(r == m.end()); |
182 | r = m.find(C2Int(7)); |
183 | assert(r == std::next(m.begin(), 3)); |
184 | r = m.find(C2Int(8)); |
185 | assert(r == m.end()); |
186 | r = m.find(C2Int(9)); |
187 | assert(r == std::next(m.begin(), 6)); |
188 | r = m.find(C2Int(10)); |
189 | assert(r == m.end()); |
190 | } |
191 | |
192 | { |
193 | typedef PrivateConstructor PC; |
194 | typedef std::multimap<PC, double, std::less<>> M; |
195 | typedef M::iterator R; |
196 | |
197 | M m; |
198 | m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 )); |
199 | m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 )); |
200 | m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 )); |
201 | m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 )); |
202 | m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 )); |
203 | m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 )); |
204 | m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 )); |
205 | m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 )); |
206 | m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 )); |
207 | |
208 | R r = m.find(5); |
209 | assert(r == m.begin()); |
210 | r = m.find(6); |
211 | assert(r == m.end()); |
212 | r = m.find(7); |
213 | assert(r == std::next(m.begin(), 3)); |
214 | r = m.find(8); |
215 | assert(r == m.end()); |
216 | r = m.find(9); |
217 | assert(r == std::next(m.begin(), 6)); |
218 | r = m.find(10); |
219 | assert(r == m.end()); |
220 | } |
221 | #endif |
222 | |
223 | return 0; |
224 | } |
225 | |