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 lower_bound(const key_type& k);
15 // const_iterator lower_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
main()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.lower_bound(4);
46 assert(r == m.begin());
47 r = m.lower_bound(5);
48 assert(r == m.begin());
49 r = m.lower_bound(6);
50 assert(r == next(m.begin(), 3));
51 r = m.lower_bound(7);
52 assert(r == next(m.begin(), 3));
53 r = m.lower_bound(8);
54 assert(r == next(m.begin(), 6));
55 r = m.lower_bound(9);
56 assert(r == next(m.begin(), 6));
57 r = m.lower_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.lower_bound(4);
76 assert(r == m.begin());
77 r = m.lower_bound(5);
78 assert(r == m.begin());
79 r = m.lower_bound(6);
80 assert(r == next(m.begin(), 3));
81 r = m.lower_bound(7);
82 assert(r == next(m.begin(), 3));
83 r = m.lower_bound(8);
84 assert(r == next(m.begin(), 6));
85 r = m.lower_bound(9);
86 assert(r == next(m.begin(), 6));
87 r = m.lower_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.lower_bound(4);
110 assert(r == m.begin());
111 r = m.lower_bound(5);
112 assert(r == m.begin());
113 r = m.lower_bound(6);
114 assert(r == next(m.begin(), 3));
115 r = m.lower_bound(7);
116 assert(r == next(m.begin(), 3));
117 r = m.lower_bound(8);
118 assert(r == next(m.begin(), 6));
119 r = m.lower_bound(9);
120 assert(r == next(m.begin(), 6));
121 r = m.lower_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.lower_bound(4);
140 assert(r == m.begin());
141 r = m.lower_bound(5);
142 assert(r == m.begin());
143 r = m.lower_bound(6);
144 assert(r == next(m.begin(), 3));
145 r = m.lower_bound(7);
146 assert(r == next(m.begin(), 3));
147 r = m.lower_bound(8);
148 assert(r == next(m.begin(), 6));
149 r = m.lower_bound(9);
150 assert(r == next(m.begin(), 6));
151 r = m.lower_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.lower_bound(4);
175 assert(r == m.begin());
176 r = m.lower_bound(5);
177 assert(r == m.begin());
178 r = m.lower_bound(6);
179 assert(r == next(m.begin(), 3));
180 r = m.lower_bound(7);
181 assert(r == next(m.begin(), 3));
182 r = m.lower_bound(8);
183 assert(r == next(m.begin(), 6));
184 r = m.lower_bound(9);
185 assert(r == next(m.begin(), 6));
186 r = m.lower_bound(10);
187 assert(r == m.end());
188
189 r = m.lower_bound(C2Int(4));
190 assert(r == m.begin());
191 r = m.lower_bound(C2Int(5));
192 assert(r == m.begin());
193 r = m.lower_bound(C2Int(6));
194 assert(r == next(m.begin(), 3));
195 r = m.lower_bound(C2Int(7));
196 assert(r == next(m.begin(), 3));
197 r = m.lower_bound(C2Int(8));
198 assert(r == next(m.begin(), 6));
199 r = m.lower_bound(C2Int(9));
200 assert(r == next(m.begin(), 6));
201 r = m.lower_bound(C2Int(10));
202 assert(r == m.end());
203 }
204
205 {
206 typedef PrivateConstructor PC;
207 typedef std::multimap<PC, double, std::less<>> M;
208 typedef M::iterator R;
209
210 M m;
211 m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
212 m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
213 m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
214 m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
215 m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
216 m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
217 m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
218 m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
219 m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
220
221 R r = m.lower_bound(4);
222 assert(r == m.begin());
223 r = m.lower_bound(5);
224 assert(r == m.begin());
225 r = m.lower_bound(6);
226 assert(r == next(m.begin(), 3));
227 r = m.lower_bound(7);
228 assert(r == next(m.begin(), 3));
229 r = m.lower_bound(8);
230 assert(r == next(m.begin(), 6));
231 r = m.lower_bound(9);
232 assert(r == next(m.begin(), 6));
233 r = m.lower_bound(10);
234 assert(r == m.end());
235 }
236
237 #endif
238 }
239