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