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"
27 typedef std::multiset
<int> M
;
29 typedef M::iterator R
;
42 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
43 R r
= m
.upper_bound(4);
44 assert(r
== std::next(m
.begin(), 0));
46 assert(r
== std::next(m
.begin(), 3));
48 assert(r
== std::next(m
.begin(), 3));
50 assert(r
== std::next(m
.begin(), 6));
52 assert(r
== std::next(m
.begin(), 6));
54 assert(r
== std::next(m
.begin(), 9));
55 r
= m
.upper_bound(11);
56 assert(r
== std::next(m
.begin(), 9));
59 typedef M::const_iterator R
;
72 const M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
73 R r
= m
.upper_bound(4);
74 assert(r
== std::next(m
.begin(), 0));
76 assert(r
== std::next(m
.begin(), 3));
78 assert(r
== std::next(m
.begin(), 3));
80 assert(r
== std::next(m
.begin(), 6));
82 assert(r
== std::next(m
.begin(), 6));
84 assert(r
== std::next(m
.begin(), 9));
85 r
= m
.upper_bound(11);
86 assert(r
== std::next(m
.begin(), 9));
89 #if TEST_STD_VER >= 11
92 typedef std::multiset
<int, std::less
<int>, min_allocator
<int>> 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
== std::next(m
.begin(), 0));
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(11);
121 assert(r
== std::next(m
.begin(), 9));
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
== std::next(m
.begin(), 0));
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(11);
151 assert(r
== std::next(m
.begin(), 9));
155 #if TEST_STD_VER > 11
158 typedef std::multiset
<V
, std::less
<>> M
;
160 typedef M::iterator R
;
173 M
m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
174 R r
= m
.upper_bound(4);
175 assert(r
== std::next(m
.begin(), 0));
176 r
= m
.upper_bound(5);
177 assert(r
== std::next(m
.begin(), 3));
178 r
= m
.upper_bound(6);
179 assert(r
== std::next(m
.begin(), 3));
180 r
= m
.upper_bound(7);
181 assert(r
== std::next(m
.begin(), 6));
182 r
= m
.upper_bound(8);
183 assert(r
== std::next(m
.begin(), 6));
184 r
= m
.upper_bound(9);
185 assert(r
== std::next(m
.begin(), 9));
186 r
= m
.upper_bound(11);
187 assert(r
== std::next(m
.begin(), 9));
191 typedef PrivateConstructor V
;
192 typedef std::multiset
<V
, std::less
<>> M
;
194 typedef M::iterator R
;
196 m
.insert ( V::make ( 5 ));
197 m
.insert ( V::make ( 5 ));
198 m
.insert ( V::make ( 5 ));
199 m
.insert ( V::make ( 7 ));
200 m
.insert ( V::make ( 7 ));
201 m
.insert ( V::make ( 7 ));
202 m
.insert ( V::make ( 9 ));
203 m
.insert ( V::make ( 9 ));
204 m
.insert ( V::make ( 9 ));
206 R r
= m
.upper_bound(4);
207 assert(r
== std::next(m
.begin(), 0));
208 r
= m
.upper_bound(5);
209 assert(r
== std::next(m
.begin(), 3));
210 r
= m
.upper_bound(6);
211 assert(r
== std::next(m
.begin(), 3));
212 r
= m
.upper_bound(7);
213 assert(r
== std::next(m
.begin(), 6));
214 r
= m
.upper_bound(8);
215 assert(r
== std::next(m
.begin(), 6));
216 r
= m
.upper_bound(9);
217 assert(r
== std::next(m
.begin(), 9));
218 r
= m
.upper_bound(11);
219 assert(r
== std::next(m
.begin(), 9));