llvm-project
237 строк · 6.5 Кб
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// <map>
10
11// class multimap
12
13// iterator upper_bound(const key_type& k);
14// const_iterator upper_bound(const key_type& k) const;
15
16#include <map>
17#include <cassert>
18
19#include "test_macros.h"
20#include "min_allocator.h"
21#include "private_constructor.h"
22#include "is_transparent.h"
23
24int main(int, char**)
25{
26typedef std::pair<const int, double> V;
27{
28typedef std::multimap<int, double> M;
29{
30typedef M::iterator R;
31V ar[] =
32{
33V(5, 1),
34V(5, 2),
35V(5, 3),
36V(7, 1),
37V(7, 2),
38V(7, 3),
39V(9, 1),
40V(9, 2),
41V(9, 3)
42};
43M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
44R r = m.upper_bound(4);
45assert(r == m.begin());
46r = m.upper_bound(5);
47assert(r == std::next(m.begin(), 3));
48r = m.upper_bound(6);
49assert(r == std::next(m.begin(), 3));
50r = m.upper_bound(7);
51assert(r == std::next(m.begin(), 6));
52r = m.upper_bound(8);
53assert(r == std::next(m.begin(), 6));
54r = m.upper_bound(9);
55assert(r == std::next(m.begin(), 9));
56r = m.upper_bound(10);
57assert(r == m.end());
58}
59{
60typedef M::const_iterator R;
61V ar[] =
62{
63V(5, 1),
64V(5, 2),
65V(5, 3),
66V(7, 1),
67V(7, 2),
68V(7, 3),
69V(9, 1),
70V(9, 2),
71V(9, 3)
72};
73const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
74R r = m.upper_bound(4);
75assert(r == m.begin());
76r = m.upper_bound(5);
77assert(r == std::next(m.begin(), 3));
78r = m.upper_bound(6);
79assert(r == std::next(m.begin(), 3));
80r = m.upper_bound(7);
81assert(r == std::next(m.begin(), 6));
82r = m.upper_bound(8);
83assert(r == std::next(m.begin(), 6));
84r = m.upper_bound(9);
85assert(r == std::next(m.begin(), 9));
86r = m.upper_bound(10);
87assert(r == m.end());
88}
89}
90#if TEST_STD_VER >= 11
91{
92typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
93{
94typedef M::iterator R;
95V ar[] =
96{
97V(5, 1),
98V(5, 2),
99V(5, 3),
100V(7, 1),
101V(7, 2),
102V(7, 3),
103V(9, 1),
104V(9, 2),
105V(9, 3)
106};
107M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
108R r = m.upper_bound(4);
109assert(r == m.begin());
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(10);
121assert(r == m.end());
122}
123{
124typedef M::const_iterator R;
125V ar[] =
126{
127V(5, 1),
128V(5, 2),
129V(5, 3),
130V(7, 1),
131V(7, 2),
132V(7, 3),
133V(9, 1),
134V(9, 2),
135V(9, 3)
136};
137const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
138R r = m.upper_bound(4);
139assert(r == m.begin());
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(10);
151assert(r == m.end());
152}
153}
154#endif
155#if TEST_STD_VER > 11
156{
157typedef std::multimap<int, double, std::less<>> M;
158typedef M::iterator R;
159V ar[] =
160{
161V(5, 1),
162V(5, 2),
163V(5, 3),
164V(7, 1),
165V(7, 2),
166V(7, 3),
167V(9, 1),
168V(9, 2),
169V(9, 3)
170};
171M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
172R r = m.upper_bound(4);
173assert(r == m.begin());
174r = m.upper_bound(5);
175assert(r == std::next(m.begin(), 3));
176r = m.upper_bound(6);
177assert(r == std::next(m.begin(), 3));
178r = m.upper_bound(7);
179assert(r == std::next(m.begin(), 6));
180r = m.upper_bound(8);
181assert(r == std::next(m.begin(), 6));
182r = m.upper_bound(9);
183assert(r == std::next(m.begin(), 9));
184r = m.upper_bound(10);
185assert(r == m.end());
186
187r = m.upper_bound(C2Int(4));
188assert(r == m.begin());
189r = m.upper_bound(C2Int(5));
190assert(r == std::next(m.begin(), 3));
191r = m.upper_bound(C2Int(6));
192assert(r == std::next(m.begin(), 3));
193r = m.upper_bound(C2Int(7));
194assert(r == std::next(m.begin(), 6));
195r = m.upper_bound(C2Int(8));
196assert(r == std::next(m.begin(), 6));
197r = m.upper_bound(C2Int(9));
198assert(r == std::next(m.begin(), 9));
199r = m.upper_bound(C2Int(10));
200}
201
202{
203typedef PrivateConstructor PC;
204typedef std::multimap<PC, double, std::less<>> M;
205typedef M::iterator R;
206
207M m;
208m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
209m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
210m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
211m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
212m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
213m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
214m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
215m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
216m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
217
218R r = m.upper_bound(4);
219assert(r == m.begin());
220r = m.upper_bound(5);
221assert(r == std::next(m.begin(), 3));
222r = m.upper_bound(6);
223assert(r == std::next(m.begin(), 3));
224r = m.upper_bound(7);
225assert(r == std::next(m.begin(), 6));
226r = m.upper_bound(8);
227assert(r == std::next(m.begin(), 6));
228r = m.upper_bound(9);
229assert(r == std::next(m.begin(), 9));
230r = m.upper_bound(10);
231assert(r == m.end());
232}
233
234#endif
235
236return 0;
237}
238