llvm-project
242 строки · 6.4 Кб
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 find(const key_type& k);
14// const_iterator find(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,
336,
347,
358,
369,
3710,
3811,
3912
40};
41M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
42R r = m.find(5);
43assert(r == m.begin());
44r = m.find(6);
45assert(r == std::next(m.begin()));
46r = m.find(7);
47assert(r == std::next(m.begin(), 2));
48r = m.find(8);
49assert(r == std::next(m.begin(), 3));
50r = m.find(9);
51assert(r == std::next(m.begin(), 4));
52r = m.find(10);
53assert(r == std::next(m.begin(), 5));
54r = m.find(11);
55assert(r == std::next(m.begin(), 6));
56r = m.find(12);
57assert(r == std::next(m.begin(), 7));
58r = m.find(4);
59assert(r == std::next(m.begin(), 8));
60}
61{
62typedef M::const_iterator R;
63V ar[] =
64{
655,
666,
677,
688,
699,
7010,
7111,
7212
73};
74const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
75R r = m.find(5);
76assert(r == m.begin());
77r = m.find(6);
78assert(r == std::next(m.begin()));
79r = m.find(7);
80assert(r == std::next(m.begin(), 2));
81r = m.find(8);
82assert(r == std::next(m.begin(), 3));
83r = m.find(9);
84assert(r == std::next(m.begin(), 4));
85r = m.find(10);
86assert(r == std::next(m.begin(), 5));
87r = m.find(11);
88assert(r == std::next(m.begin(), 6));
89r = m.find(12);
90assert(r == std::next(m.begin(), 7));
91r = m.find(4);
92assert(r == std::next(m.begin(), 8));
93}
94}
95#if TEST_STD_VER >= 11
96{
97typedef int V;
98typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
99{
100typedef M::iterator R;
101V ar[] =
102{
1035,
1046,
1057,
1068,
1079,
10810,
10911,
11012
111};
112M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
113R r = m.find(5);
114assert(r == m.begin());
115r = m.find(6);
116assert(r == std::next(m.begin()));
117r = m.find(7);
118assert(r == std::next(m.begin(), 2));
119r = m.find(8);
120assert(r == std::next(m.begin(), 3));
121r = m.find(9);
122assert(r == std::next(m.begin(), 4));
123r = m.find(10);
124assert(r == std::next(m.begin(), 5));
125r = m.find(11);
126assert(r == std::next(m.begin(), 6));
127r = m.find(12);
128assert(r == std::next(m.begin(), 7));
129r = m.find(4);
130assert(r == std::next(m.begin(), 8));
131}
132{
133typedef M::const_iterator R;
134V ar[] =
135{
1365,
1376,
1387,
1398,
1409,
14110,
14211,
14312
144};
145const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
146R r = m.find(5);
147assert(r == m.begin());
148r = m.find(6);
149assert(r == std::next(m.begin()));
150r = m.find(7);
151assert(r == std::next(m.begin(), 2));
152r = m.find(8);
153assert(r == std::next(m.begin(), 3));
154r = m.find(9);
155assert(r == std::next(m.begin(), 4));
156r = m.find(10);
157assert(r == std::next(m.begin(), 5));
158r = m.find(11);
159assert(r == std::next(m.begin(), 6));
160r = m.find(12);
161assert(r == std::next(m.begin(), 7));
162r = m.find(4);
163assert(r == std::next(m.begin(), 8));
164}
165}
166#endif
167#if TEST_STD_VER > 11
168{
169typedef int V;
170typedef std::multiset<V, std::less<>> M;
171typedef M::iterator R;
172
173V ar[] =
174{
1755,
1766,
1777,
1788,
1799,
18010,
18111,
18212
183};
184M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
185R r = m.find(5);
186assert(r == m.begin());
187r = m.find(6);
188assert(r == std::next(m.begin()));
189r = m.find(7);
190assert(r == std::next(m.begin(), 2));
191r = m.find(8);
192assert(r == std::next(m.begin(), 3));
193r = m.find(9);
194assert(r == std::next(m.begin(), 4));
195r = m.find(10);
196assert(r == std::next(m.begin(), 5));
197r = m.find(11);
198assert(r == std::next(m.begin(), 6));
199r = m.find(12);
200assert(r == std::next(m.begin(), 7));
201r = m.find(4);
202assert(r == std::next(m.begin(), 8));
203}
204
205{
206typedef PrivateConstructor V;
207typedef std::multiset<V, std::less<>> M;
208typedef M::iterator R;
209
210M m;
211m.insert ( V::make ( 5 ));
212m.insert ( V::make ( 6 ));
213m.insert ( V::make ( 7 ));
214m.insert ( V::make ( 8 ));
215m.insert ( V::make ( 9 ));
216m.insert ( V::make ( 10 ));
217m.insert ( V::make ( 11 ));
218m.insert ( V::make ( 12 ));
219
220R r = m.find(5);
221assert(r == m.begin());
222r = m.find(6);
223assert(r == std::next(m.begin()));
224r = m.find(7);
225assert(r == std::next(m.begin(), 2));
226r = m.find(8);
227assert(r == std::next(m.begin(), 3));
228r = m.find(9);
229assert(r == std::next(m.begin(), 4));
230r = m.find(10);
231assert(r == std::next(m.begin(), 5));
232r = m.find(11);
233assert(r == std::next(m.begin(), 6));
234r = m.find(12);
235assert(r == std::next(m.begin(), 7));
236r = m.find(4);
237assert(r == std::next(m.begin(), 8));
238}
239#endif
240
241return 0;
242}
243