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 upper_bound(const key_type& k);
14 // const_iterator upper_bound(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"
26 typedef std::pair
<const int, double> V
;
28 typedef std::multimap
<int, double> M
;
30 typedef M::iterator R
;
43 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
44 R r
= m
.upper_bound(4);
45 assert(r
== m
.begin());
47 assert(r
== std::next(m
.begin(), 3));
49 assert(r
== std::next(m
.begin(), 3));
51 assert(r
== std::next(m
.begin(), 6));
53 assert(r
== std::next(m
.begin(), 6));
55 assert(r
== std::next(m
.begin(), 9));
56 r
= m
.upper_bound(10);
60 typedef M::const_iterator R
;
73 const M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
74 R r
= m
.upper_bound(4);
75 assert(r
== m
.begin());
77 assert(r
== std::next(m
.begin(), 3));
79 assert(r
== std::next(m
.begin(), 3));
81 assert(r
== std::next(m
.begin(), 6));
83 assert(r
== std::next(m
.begin(), 6));
85 assert(r
== std::next(m
.begin(), 9));
86 r
= m
.upper_bound(10);
90 #if TEST_STD_VER >= 11
92 typedef std::multimap
<int, double, std::less
<int>, min_allocator
<std::pair
<const int, double>>> M
;
94 typedef M::iterator R
;
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());
124 typedef M::const_iterator R
;
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());
155 #if TEST_STD_VER > 11
157 typedef std::multimap
<int, double, std::less
<>> M
;
158 typedef M::iterator R
;
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());
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));
203 typedef PrivateConstructor PC
;
204 typedef std::multimap
<PC
, double, std::less
<>> M
;
205 typedef M::iterator R
;
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 ));
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());