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