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

source code of libcxx/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp