llvm-project
224 строки · 5.6 Кб
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// <set>
10
11// class multiset
12
13// iterator upper_bound(const key_type& k);
14// const_iterator upper_bound(const key_type& k) const;
15
16#include <set>
17#include <cassert>
18
19#include "test_macros.h"
20#include "min_allocator.h"
21#include "private_constructor.h"
22
23int main(int, char**)
24{
25{
26typedef int V;
27typedef std::multiset<int> M;
28{
29typedef M::iterator R;
30V ar[] =
31{
325,
335,
345,
357,
367,
377,
389,
399,
409
41};
42M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
43R r = m.upper_bound(4);
44assert(r == std::next(m.begin(), 0));
45r = m.upper_bound(5);
46assert(r == std::next(m.begin(), 3));
47r = m.upper_bound(6);
48assert(r == std::next(m.begin(), 3));
49r = m.upper_bound(7);
50assert(r == std::next(m.begin(), 6));
51r = m.upper_bound(8);
52assert(r == std::next(m.begin(), 6));
53r = m.upper_bound(9);
54assert(r == std::next(m.begin(), 9));
55r = m.upper_bound(11);
56assert(r == std::next(m.begin(), 9));
57}
58{
59typedef M::const_iterator R;
60V ar[] =
61{
625,
635,
645,
657,
667,
677,
689,
699,
709
71};
72const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
73R r = m.upper_bound(4);
74assert(r == std::next(m.begin(), 0));
75r = m.upper_bound(5);
76assert(r == std::next(m.begin(), 3));
77r = m.upper_bound(6);
78assert(r == std::next(m.begin(), 3));
79r = m.upper_bound(7);
80assert(r == std::next(m.begin(), 6));
81r = m.upper_bound(8);
82assert(r == std::next(m.begin(), 6));
83r = m.upper_bound(9);
84assert(r == std::next(m.begin(), 9));
85r = m.upper_bound(11);
86assert(r == std::next(m.begin(), 9));
87}
88}
89#if TEST_STD_VER >= 11
90{
91typedef int V;
92typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
93{
94typedef M::iterator R;
95V ar[] =
96{
975,
985,
995,
1007,
1017,
1027,
1039,
1049,
1059
106};
107M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
108R r = m.upper_bound(4);
109assert(r == std::next(m.begin(), 0));
110r = m.upper_bound(5);
111assert(r == std::next(m.begin(), 3));
112r = m.upper_bound(6);
113assert(r == std::next(m.begin(), 3));
114r = m.upper_bound(7);
115assert(r == std::next(m.begin(), 6));
116r = m.upper_bound(8);
117assert(r == std::next(m.begin(), 6));
118r = m.upper_bound(9);
119assert(r == std::next(m.begin(), 9));
120r = m.upper_bound(11);
121assert(r == std::next(m.begin(), 9));
122}
123{
124typedef M::const_iterator R;
125V ar[] =
126{
1275,
1285,
1295,
1307,
1317,
1327,
1339,
1349,
1359
136};
137const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
138R r = m.upper_bound(4);
139assert(r == std::next(m.begin(), 0));
140r = m.upper_bound(5);
141assert(r == std::next(m.begin(), 3));
142r = m.upper_bound(6);
143assert(r == std::next(m.begin(), 3));
144r = m.upper_bound(7);
145assert(r == std::next(m.begin(), 6));
146r = m.upper_bound(8);
147assert(r == std::next(m.begin(), 6));
148r = m.upper_bound(9);
149assert(r == std::next(m.begin(), 9));
150r = m.upper_bound(11);
151assert(r == std::next(m.begin(), 9));
152}
153}
154#endif
155#if TEST_STD_VER > 11
156{
157typedef int V;
158typedef std::multiset<V, std::less<>> M;
159
160typedef M::iterator R;
161V ar[] =
162{
1635,
1645,
1655,
1667,
1677,
1687,
1699,
1709,
1719
172};
173M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
174R r = m.upper_bound(4);
175assert(r == std::next(m.begin(), 0));
176r = m.upper_bound(5);
177assert(r == std::next(m.begin(), 3));
178r = m.upper_bound(6);
179assert(r == std::next(m.begin(), 3));
180r = m.upper_bound(7);
181assert(r == std::next(m.begin(), 6));
182r = m.upper_bound(8);
183assert(r == std::next(m.begin(), 6));
184r = m.upper_bound(9);
185assert(r == std::next(m.begin(), 9));
186r = m.upper_bound(11);
187assert(r == std::next(m.begin(), 9));
188}
189
190{
191typedef PrivateConstructor V;
192typedef std::multiset<V, std::less<>> M;
193
194typedef M::iterator R;
195M m;
196m.insert ( V::make ( 5 ));
197m.insert ( V::make ( 5 ));
198m.insert ( V::make ( 5 ));
199m.insert ( V::make ( 7 ));
200m.insert ( V::make ( 7 ));
201m.insert ( V::make ( 7 ));
202m.insert ( V::make ( 9 ));
203m.insert ( V::make ( 9 ));
204m.insert ( V::make ( 9 ));
205
206R r = m.upper_bound(4);
207assert(r == std::next(m.begin(), 0));
208r = m.upper_bound(5);
209assert(r == std::next(m.begin(), 3));
210r = m.upper_bound(6);
211assert(r == std::next(m.begin(), 3));
212r = m.upper_bound(7);
213assert(r == std::next(m.begin(), 6));
214r = m.upper_bound(8);
215assert(r == std::next(m.begin(), 6));
216r = m.upper_bound(9);
217assert(r == std::next(m.begin(), 9));
218r = m.upper_bound(11);
219assert(r == std::next(m.begin(), 9));
220}
221#endif
222
223return 0;
224}
225