llvm-project
225 строк · 6.1 Кб
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 lower_bound(const key_type& k);
14// const_iterator lower_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.lower_bound(4);
44assert(r == std::next(m.begin(), 0));
45r = m.lower_bound(5);
46assert(r == std::next(m.begin(), 0));
47r = m.lower_bound(6);
48assert(r == std::next(m.begin(), 3));
49r = m.lower_bound(7);
50assert(r == std::next(m.begin(), 3));
51r = m.lower_bound(8);
52assert(r == std::next(m.begin(), 6));
53r = m.lower_bound(9);
54assert(r == std::next(m.begin(), 6));
55r = m.lower_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.lower_bound(4);
74assert(r == std::next(m.begin(), 0));
75r = m.lower_bound(5);
76assert(r == std::next(m.begin(), 0));
77r = m.lower_bound(6);
78assert(r == std::next(m.begin(), 3));
79r = m.lower_bound(7);
80assert(r == std::next(m.begin(), 3));
81r = m.lower_bound(8);
82assert(r == std::next(m.begin(), 6));
83r = m.lower_bound(9);
84assert(r == std::next(m.begin(), 6));
85r = m.lower_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.lower_bound(4);
109assert(r == std::next(m.begin(), 0));
110r = m.lower_bound(5);
111assert(r == std::next(m.begin(), 0));
112r = m.lower_bound(6);
113assert(r == std::next(m.begin(), 3));
114r = m.lower_bound(7);
115assert(r == std::next(m.begin(), 3));
116r = m.lower_bound(8);
117assert(r == std::next(m.begin(), 6));
118r = m.lower_bound(9);
119assert(r == std::next(m.begin(), 6));
120r = m.lower_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.lower_bound(4);
139assert(r == std::next(m.begin(), 0));
140r = m.lower_bound(5);
141assert(r == std::next(m.begin(), 0));
142r = m.lower_bound(6);
143assert(r == std::next(m.begin(), 3));
144r = m.lower_bound(7);
145assert(r == std::next(m.begin(), 3));
146r = m.lower_bound(8);
147assert(r == std::next(m.begin(), 6));
148r = m.lower_bound(9);
149assert(r == std::next(m.begin(), 6));
150r = m.lower_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]));
174
175R r = m.lower_bound(4);
176assert(r == std::next(m.begin(), 0));
177r = m.lower_bound(5);
178assert(r == std::next(m.begin(), 0));
179r = m.lower_bound(6);
180assert(r == std::next(m.begin(), 3));
181r = m.lower_bound(7);
182assert(r == std::next(m.begin(), 3));
183r = m.lower_bound(8);
184assert(r == std::next(m.begin(), 6));
185r = m.lower_bound(9);
186assert(r == std::next(m.begin(), 6));
187r = m.lower_bound(11);
188assert(r == std::next(m.begin(), 9));
189}
190
191{
192typedef PrivateConstructor V;
193typedef std::multiset<V, std::less<>> M;
194typedef M::iterator R;
195
196M m;
197m.insert ( V::make ( 5 ));
198m.insert ( V::make ( 5 ));
199m.insert ( V::make ( 5 ));
200m.insert ( V::make ( 7 ));
201m.insert ( V::make ( 7 ));
202m.insert ( V::make ( 7 ));
203m.insert ( V::make ( 9 ));
204m.insert ( V::make ( 9 ));
205m.insert ( V::make ( 9 ));
206
207R r = m.lower_bound(4);
208assert(r == std::next(m.begin(), 0));
209r = m.lower_bound(5);
210assert(r == std::next(m.begin(), 0));
211r = m.lower_bound(6);
212assert(r == std::next(m.begin(), 3));
213r = m.lower_bound(7);
214assert(r == std::next(m.begin(), 3));
215r = m.lower_bound(8);
216assert(r == std::next(m.begin(), 6));
217r = m.lower_bound(9);
218assert(r == std::next(m.begin(), 6));
219r = m.lower_bound(11);
220assert(r == std::next(m.begin(), 9));
221}
222#endif
223
224return 0;
225}
226