]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / containers / associative / multimap / multimap.ops / upper_bound.pass.cpp
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <map>
11
12 // class multimap
13
14 //       iterator upper_bound(const key_type& k);
15 // const_iterator upper_bound(const key_type& k) const;
16
17 #include <map>
18 #include <cassert>
19
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 #include "private_constructor.hpp"
23 #include "is_transparent.h"
24
25 int main()
26 {
27     typedef std::pair<const int, double> V;
28     {
29     typedef std::multimap<int, double> M;
30     {
31         typedef M::iterator R;
32         V ar[] =
33         {
34             V(5, 1),
35             V(5, 2),
36             V(5, 3),
37             V(7, 1),
38             V(7, 2),
39             V(7, 3),
40             V(9, 1),
41             V(9, 2),
42             V(9, 3)
43         };
44         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
45         R r = m.upper_bound(4);
46         assert(r == m.begin());
47         r = m.upper_bound(5);
48         assert(r == next(m.begin(), 3));
49         r = m.upper_bound(6);
50         assert(r == next(m.begin(), 3));
51         r = m.upper_bound(7);
52         assert(r == next(m.begin(), 6));
53         r = m.upper_bound(8);
54         assert(r == next(m.begin(), 6));
55         r = m.upper_bound(9);
56         assert(r == next(m.begin(), 9));
57         r = m.upper_bound(10);
58         assert(r == m.end());
59     }
60     {
61         typedef M::const_iterator R;
62         V ar[] =
63         {
64             V(5, 1),
65             V(5, 2),
66             V(5, 3),
67             V(7, 1),
68             V(7, 2),
69             V(7, 3),
70             V(9, 1),
71             V(9, 2),
72             V(9, 3)
73         };
74         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
75         R r = m.upper_bound(4);
76         assert(r == m.begin());
77         r = m.upper_bound(5);
78         assert(r == next(m.begin(), 3));
79         r = m.upper_bound(6);
80         assert(r == next(m.begin(), 3));
81         r = m.upper_bound(7);
82         assert(r == next(m.begin(), 6));
83         r = m.upper_bound(8);
84         assert(r == next(m.begin(), 6));
85         r = m.upper_bound(9);
86         assert(r == next(m.begin(), 9));
87         r = m.upper_bound(10);
88         assert(r == m.end());
89     }
90     }
91 #if TEST_STD_VER >= 11
92     {
93     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
94     {
95         typedef M::iterator R;
96         V ar[] =
97         {
98             V(5, 1),
99             V(5, 2),
100             V(5, 3),
101             V(7, 1),
102             V(7, 2),
103             V(7, 3),
104             V(9, 1),
105             V(9, 2),
106             V(9, 3)
107         };
108         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
109         R r = m.upper_bound(4);
110         assert(r == m.begin());
111         r = m.upper_bound(5);
112         assert(r == next(m.begin(), 3));
113         r = m.upper_bound(6);
114         assert(r == next(m.begin(), 3));
115         r = m.upper_bound(7);
116         assert(r == next(m.begin(), 6));
117         r = m.upper_bound(8);
118         assert(r == next(m.begin(), 6));
119         r = m.upper_bound(9);
120         assert(r == next(m.begin(), 9));
121         r = m.upper_bound(10);
122         assert(r == m.end());
123     }
124     {
125         typedef M::const_iterator R;
126         V ar[] =
127         {
128             V(5, 1),
129             V(5, 2),
130             V(5, 3),
131             V(7, 1),
132             V(7, 2),
133             V(7, 3),
134             V(9, 1),
135             V(9, 2),
136             V(9, 3)
137         };
138         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
139         R r = m.upper_bound(4);
140         assert(r == m.begin());
141         r = m.upper_bound(5);
142         assert(r == next(m.begin(), 3));
143         r = m.upper_bound(6);
144         assert(r == next(m.begin(), 3));
145         r = m.upper_bound(7);
146         assert(r == next(m.begin(), 6));
147         r = m.upper_bound(8);
148         assert(r == next(m.begin(), 6));
149         r = m.upper_bound(9);
150         assert(r == next(m.begin(), 9));
151         r = m.upper_bound(10);
152         assert(r == m.end());
153     }
154     }
155 #endif
156 #if TEST_STD_VER > 11
157     {
158     typedef std::pair<const int, double> V;
159     typedef std::multimap<int, double, std::less<>> M;
160     typedef M::iterator R;
161     V ar[] =
162     {
163         V(5, 1),
164         V(5, 2),
165         V(5, 3),
166         V(7, 1),
167         V(7, 2),
168         V(7, 3),
169         V(9, 1),
170         V(9, 2),
171         V(9, 3)
172     };
173     M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
174     R r = m.upper_bound(4);
175     assert(r == m.begin());
176     r = m.upper_bound(5);
177     assert(r == next(m.begin(), 3));
178     r = m.upper_bound(6);
179     assert(r == next(m.begin(), 3));
180     r = m.upper_bound(7);
181     assert(r == next(m.begin(), 6));
182     r = m.upper_bound(8);
183     assert(r == next(m.begin(), 6));
184     r = m.upper_bound(9);
185     assert(r == next(m.begin(), 9));
186     r = m.upper_bound(10);
187     assert(r == m.end());
188
189     r = m.upper_bound(C2Int(4));
190     assert(r == m.begin());
191     r = m.upper_bound(C2Int(5));
192     assert(r == next(m.begin(), 3));
193     r = m.upper_bound(C2Int(6));
194     assert(r == next(m.begin(), 3));
195     r = m.upper_bound(C2Int(7));
196     assert(r == next(m.begin(), 6));
197     r = m.upper_bound(C2Int(8));
198     assert(r == next(m.begin(), 6));
199     r = m.upper_bound(C2Int(9));
200     assert(r == next(m.begin(), 9));
201     r = m.upper_bound(C2Int(10));
202     }
203
204     {
205     typedef PrivateConstructor PC;
206     typedef std::multimap<PC, double, std::less<>> M;
207     typedef M::iterator R;
208
209     M m;
210     m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
211     m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
212     m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
213     m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
214     m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
215     m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
216     m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
217     m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
218     m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
219
220     R r = m.upper_bound(4);
221     assert(r == m.begin());
222     r = m.upper_bound(5);
223     assert(r == next(m.begin(), 3));
224     r = m.upper_bound(6);
225     assert(r == next(m.begin(), 3));
226     r = m.upper_bound(7);
227     assert(r == next(m.begin(), 6));
228     r = m.upper_bound(8);
229     assert(r == next(m.begin(), 6));
230     r = m.upper_bound(9);
231     assert(r == next(m.begin(), 9));
232     r = m.upper_bound(10);
233     assert(r == m.end());
234     }
235
236 #endif
237 }