• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <multimap>
11 
12 // class multimap
13 
14 // pair<iterator, iterator>             equal_range(const key_type& k);
15 // pair<const_iterator, const_iterator> equal_range(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 std::pair<M::iterator, 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.equal_range(4);
46         assert(r.first == m.begin());
47         assert(r.second == m.begin());
48         r = m.equal_range(5);
49         assert(r.first == m.begin());
50         assert(r.second == next(m.begin(), 3));
51         r = m.equal_range(6);
52         assert(r.first == next(m.begin(), 3));
53         assert(r.second == next(m.begin(), 3));
54         r = m.equal_range(7);
55         assert(r.first == next(m.begin(), 3));
56         assert(r.second == next(m.begin(), 6));
57         r = m.equal_range(8);
58         assert(r.first == next(m.begin(), 6));
59         assert(r.second == next(m.begin(), 6));
60         r = m.equal_range(9);
61         assert(r.first == next(m.begin(), 6));
62         assert(r.second == next(m.begin(), 9));
63         r = m.equal_range(10);
64         assert(r.first == m.end());
65         assert(r.second == m.end());
66     }
67     {
68         typedef std::pair<M::const_iterator, M::const_iterator> R;
69         V ar[] =
70         {
71             V(5, 1),
72             V(5, 2),
73             V(5, 3),
74             V(7, 1),
75             V(7, 2),
76             V(7, 3),
77             V(9, 1),
78             V(9, 2),
79             V(9, 3)
80         };
81         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
82         R r = m.equal_range(4);
83         assert(r.first == m.begin());
84         assert(r.second == m.begin());
85         r = m.equal_range(5);
86         assert(r.first == m.begin());
87         assert(r.second == next(m.begin(), 3));
88         r = m.equal_range(6);
89         assert(r.first == next(m.begin(), 3));
90         assert(r.second == next(m.begin(), 3));
91         r = m.equal_range(7);
92         assert(r.first == next(m.begin(), 3));
93         assert(r.second == next(m.begin(), 6));
94         r = m.equal_range(8);
95         assert(r.first == next(m.begin(), 6));
96         assert(r.second == next(m.begin(), 6));
97         r = m.equal_range(9);
98         assert(r.first == next(m.begin(), 6));
99         assert(r.second == next(m.begin(), 9));
100         r = m.equal_range(10);
101         assert(r.first == m.end());
102         assert(r.second == m.end());
103     }
104     }
105 #if TEST_STD_VER >= 11
106     {
107     typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M;
108     {
109         typedef std::pair<M::iterator, M::iterator> R;
110         V ar[] =
111         {
112             V(5, 1),
113             V(5, 2),
114             V(5, 3),
115             V(7, 1),
116             V(7, 2),
117             V(7, 3),
118             V(9, 1),
119             V(9, 2),
120             V(9, 3)
121         };
122         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
123         R r = m.equal_range(4);
124         assert(r.first == m.begin());
125         assert(r.second == m.begin());
126         r = m.equal_range(5);
127         assert(r.first == m.begin());
128         assert(r.second == next(m.begin(), 3));
129         r = m.equal_range(6);
130         assert(r.first == next(m.begin(), 3));
131         assert(r.second == next(m.begin(), 3));
132         r = m.equal_range(7);
133         assert(r.first == next(m.begin(), 3));
134         assert(r.second == next(m.begin(), 6));
135         r = m.equal_range(8);
136         assert(r.first == next(m.begin(), 6));
137         assert(r.second == next(m.begin(), 6));
138         r = m.equal_range(9);
139         assert(r.first == next(m.begin(), 6));
140         assert(r.second == next(m.begin(), 9));
141         r = m.equal_range(10);
142         assert(r.first == m.end());
143         assert(r.second == m.end());
144     }
145     {
146         typedef std::pair<M::const_iterator, M::const_iterator> R;
147         V ar[] =
148         {
149             V(5, 1),
150             V(5, 2),
151             V(5, 3),
152             V(7, 1),
153             V(7, 2),
154             V(7, 3),
155             V(9, 1),
156             V(9, 2),
157             V(9, 3)
158         };
159         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
160         R r = m.equal_range(4);
161         assert(r.first == m.begin());
162         assert(r.second == m.begin());
163         r = m.equal_range(5);
164         assert(r.first == m.begin());
165         assert(r.second == next(m.begin(), 3));
166         r = m.equal_range(6);
167         assert(r.first == next(m.begin(), 3));
168         assert(r.second == next(m.begin(), 3));
169         r = m.equal_range(7);
170         assert(r.first == next(m.begin(), 3));
171         assert(r.second == next(m.begin(), 6));
172         r = m.equal_range(8);
173         assert(r.first == next(m.begin(), 6));
174         assert(r.second == next(m.begin(), 6));
175         r = m.equal_range(9);
176         assert(r.first == next(m.begin(), 6));
177         assert(r.second == next(m.begin(), 9));
178         r = m.equal_range(10);
179         assert(r.first == m.end());
180         assert(r.second == m.end());
181     }
182     }
183 #endif
184 #if TEST_STD_VER > 11
185     {
186     typedef std::multimap<int, double, std::less<>> M;
187 
188     typedef std::pair<M::iterator, M::iterator> R;
189     V ar[] =
190     {
191         V(5, 1),
192         V(5, 2),
193         V(5, 3),
194         V(7, 1),
195         V(7, 2),
196         V(7, 3),
197         V(9, 1),
198         V(9, 2),
199         V(9, 3)
200     };
201     M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
202     R r = m.equal_range(4);
203     assert(r.first == m.begin());
204     assert(r.second == m.begin());
205     r = m.equal_range(5);
206     assert(r.first == m.begin());
207     assert(r.second == next(m.begin(), 3));
208     r = m.equal_range(6);
209     assert(r.first == next(m.begin(), 3));
210     assert(r.second == next(m.begin(), 3));
211     r = m.equal_range(7);
212     assert(r.first == next(m.begin(), 3));
213     assert(r.second == next(m.begin(), 6));
214     r = m.equal_range(8);
215     assert(r.first == next(m.begin(), 6));
216     assert(r.second == next(m.begin(), 6));
217     r = m.equal_range(9);
218     assert(r.first == next(m.begin(), 6));
219     assert(r.second == next(m.begin(), 9));
220     r = m.equal_range(10);
221     assert(r.first == m.end());
222     assert(r.second == m.end());
223 
224     r = m.equal_range(C2Int(4));
225     assert(r.first == m.begin());
226     assert(r.second == m.begin());
227     r = m.equal_range(C2Int(5));
228     assert(r.first == m.begin());
229     assert(r.second == next(m.begin(), 3));
230     r = m.equal_range(C2Int(6));
231     assert(r.first == next(m.begin(), 3));
232     assert(r.second == next(m.begin(), 3));
233     r = m.equal_range(C2Int(7));
234     assert(r.first == next(m.begin(), 3));
235     assert(r.second == next(m.begin(), 6));
236     r = m.equal_range(C2Int(8));
237     assert(r.first == next(m.begin(), 6));
238     assert(r.second == next(m.begin(), 6));
239     r = m.equal_range(C2Int(9));
240     assert(r.first == next(m.begin(), 6));
241     assert(r.second == next(m.begin(), 9));
242     r = m.equal_range(C2Int(10));
243     assert(r.first == m.end());
244     assert(r.second == m.end());
245     }
246 
247     {
248     typedef PrivateConstructor PC;
249     typedef std::multimap<PC, double, std::less<>> M;
250     typedef std::pair<M::iterator, M::iterator> R;
251 
252     M m;
253     m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 ));
254     m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 ));
255     m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 ));
256     m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 ));
257     m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 ));
258     m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 ));
259     m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 ));
260     m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 ));
261     m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 ));
262 
263 //  assert(m.size() == 9);
264     R r = m.equal_range(4);
265     assert(r.first == m.begin());
266     assert(r.second == m.begin());
267     r = m.equal_range(5);
268     assert(r.first == m.begin());
269     assert(r.second == next(m.begin(), 3));
270     r = m.equal_range(6);
271     assert(r.first == next(m.begin(), 3));
272     assert(r.second == next(m.begin(), 3));
273     r = m.equal_range(7);
274     assert(r.first == next(m.begin(), 3));
275     assert(r.second == next(m.begin(), 6));
276     r = m.equal_range(8);
277     assert(r.first == next(m.begin(), 6));
278     assert(r.second == next(m.begin(), 6));
279     r = m.equal_range(9);
280     assert(r.first == next(m.begin(), 6));
281     assert(r.second == next(m.begin(), 9));
282     r = m.equal_range(10);
283     assert(r.first == m.end());
284     assert(r.second == m.end());
285     }
286 #endif
287 }
288