• 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 // <set>
11 
12 // class multiset
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 <set>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 #include "min_allocator.h"
22 #include "private_constructor.hpp"
23 
main()24 int main()
25 {
26     {
27     typedef int V;
28     typedef std::multiset<int> M;
29     {
30         typedef std::pair<M::iterator, M::iterator> R;
31         V ar[] =
32         {
33             5,
34             5,
35             5,
36             7,
37             7,
38             7,
39             9,
40             9,
41             9
42         };
43         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
44         R r = m.equal_range(4);
45         assert(r.first  == next(m.begin(), 0));
46         assert(r.second == next(m.begin(), 0));
47         r = m.equal_range(5);
48         assert(r.first  == next(m.begin(), 0));
49         assert(r.second == next(m.begin(), 3));
50         r = m.equal_range(6);
51         assert(r.first  == next(m.begin(), 3));
52         assert(r.second == next(m.begin(), 3));
53         r = m.equal_range(7);
54         assert(r.first  == next(m.begin(), 3));
55         assert(r.second == next(m.begin(), 6));
56         r = m.equal_range(8);
57         assert(r.first  == next(m.begin(), 6));
58         assert(r.second == next(m.begin(), 6));
59         r = m.equal_range(9);
60         assert(r.first  == next(m.begin(), 6));
61         assert(r.second == next(m.begin(), 9));
62         r = m.equal_range(10);
63         assert(r.first  == next(m.begin(), 9));
64         assert(r.second == next(m.begin(), 9));
65     }
66     {
67         typedef std::pair<M::const_iterator, M::const_iterator> R;
68         V ar[] =
69         {
70             5,
71             5,
72             5,
73             7,
74             7,
75             7,
76             9,
77             9,
78             9
79         };
80         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
81         R r = m.equal_range(4);
82         assert(r.first  == next(m.begin(), 0));
83         assert(r.second == next(m.begin(), 0));
84         r = m.equal_range(5);
85         assert(r.first  == next(m.begin(), 0));
86         assert(r.second == next(m.begin(), 3));
87         r = m.equal_range(6);
88         assert(r.first  == next(m.begin(), 3));
89         assert(r.second == next(m.begin(), 3));
90         r = m.equal_range(7);
91         assert(r.first  == next(m.begin(), 3));
92         assert(r.second == next(m.begin(), 6));
93         r = m.equal_range(8);
94         assert(r.first  == next(m.begin(), 6));
95         assert(r.second == next(m.begin(), 6));
96         r = m.equal_range(9);
97         assert(r.first  == next(m.begin(), 6));
98         assert(r.second == next(m.begin(), 9));
99         r = m.equal_range(10);
100         assert(r.first  == next(m.begin(), 9));
101         assert(r.second == next(m.begin(), 9));
102     }
103     }
104 #if TEST_STD_VER >= 11
105     {
106     typedef int V;
107     typedef std::multiset<int, std::less<int>, min_allocator<int>> M;
108     {
109         typedef std::pair<M::iterator, M::iterator> R;
110         V ar[] =
111         {
112             5,
113             5,
114             5,
115             7,
116             7,
117             7,
118             9,
119             9,
120             9
121         };
122         M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
123         R r = m.equal_range(4);
124         assert(r.first  == next(m.begin(), 0));
125         assert(r.second == next(m.begin(), 0));
126         r = m.equal_range(5);
127         assert(r.first  == next(m.begin(), 0));
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  == next(m.begin(), 9));
143         assert(r.second == next(m.begin(), 9));
144     }
145     {
146         typedef std::pair<M::const_iterator, M::const_iterator> R;
147         V ar[] =
148         {
149             5,
150             5,
151             5,
152             7,
153             7,
154             7,
155             9,
156             9,
157             9
158         };
159         const M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
160         R r = m.equal_range(4);
161         assert(r.first  == next(m.begin(), 0));
162         assert(r.second == next(m.begin(), 0));
163         r = m.equal_range(5);
164         assert(r.first  == next(m.begin(), 0));
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  == next(m.begin(), 9));
180         assert(r.second == next(m.begin(), 9));
181     }
182     }
183 #endif
184 #if TEST_STD_VER > 11
185     {
186     typedef int V;
187     typedef std::multiset<V, std::less<>> M;
188     typedef std::pair<M::iterator, M::iterator> R;
189     V ar[] =
190     {
191         5,
192         5,
193         5,
194         7,
195         7,
196         7,
197         9,
198         9,
199         9
200     };
201     M m(ar, ar+sizeof(ar)/sizeof(ar[0]));
202     R r = m.equal_range(4);
203     assert(r.first  == next(m.begin(), 0));
204     assert(r.second == next(m.begin(), 0));
205     r = m.equal_range(5);
206     assert(r.first  == next(m.begin(), 0));
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  == next(m.begin(), 9));
222     assert(r.second == next(m.begin(), 9));
223     }
224 
225     {
226     typedef PrivateConstructor V;
227     typedef std::multiset<V, std::less<>> M;
228     typedef std::pair<M::iterator, M::iterator> R;
229 
230     M m;
231     m.insert ( V::make ( 5 ));
232     m.insert ( V::make ( 5 ));
233     m.insert ( V::make ( 5 ));
234     m.insert ( V::make ( 7 ));
235     m.insert ( V::make ( 7 ));
236     m.insert ( V::make ( 7 ));
237     m.insert ( V::make ( 9 ));
238     m.insert ( V::make ( 9 ));
239     m.insert ( V::make ( 9 ));
240 
241     R r = m.equal_range(4);
242     assert(r.first  == next(m.begin(), 0));
243     assert(r.second == next(m.begin(), 0));
244     r = m.equal_range(5);
245     assert(r.first  == next(m.begin(), 0));
246     assert(r.second == next(m.begin(), 3));
247     r = m.equal_range(6);
248     assert(r.first  == next(m.begin(), 3));
249     assert(r.second == next(m.begin(), 3));
250     r = m.equal_range(7);
251     assert(r.first  == next(m.begin(), 3));
252     assert(r.second == next(m.begin(), 6));
253     r = m.equal_range(8);
254     assert(r.first  == next(m.begin(), 6));
255     assert(r.second == next(m.begin(), 6));
256     r = m.equal_range(9);
257     assert(r.first  == next(m.begin(), 6));
258     assert(r.second == next(m.begin(), 9));
259     r = m.equal_range(10);
260     assert(r.first  == next(m.begin(), 9));
261     assert(r.second == next(m.begin(), 9));
262     }
263 #endif
264 }
265