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