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 begin();
15 // const_iterator begin() const;
16 // iterator end();
17 // const_iterator end() const;
18 //
19 // reverse_iterator rbegin();
20 // const_reverse_iterator rbegin() const;
21 // reverse_iterator rend();
22 // const_reverse_iterator rend() const;
23 //
24 // const_iterator cbegin() const;
25 // const_iterator cend() const;
26 // const_reverse_iterator crbegin() const;
27 // const_reverse_iterator crend() const;
28
29 #include <set>
30 #include <cassert>
31
32 #include "min_allocator.h"
33
main()34 int main()
35 {
36 {
37 typedef int V;
38 V ar[] =
39 {
40 1,
41 1,
42 1,
43 2,
44 2,
45 2,
46 3,
47 3,
48 3,
49 4,
50 4,
51 4,
52 5,
53 5,
54 5,
55 6,
56 6,
57 6,
58 7,
59 7,
60 7,
61 8,
62 8,
63 8
64 };
65 std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
66 assert(std::distance(m.begin(), m.end()) == m.size());
67 assert(std::distance(m.rbegin(), m.rend()) == m.size());
68 std::set<int>::iterator i;
69 i = m.begin();
70 std::set<int>::const_iterator k = i;
71 assert(i == k);
72 for (int j = 1; j <= m.size(); ++j, ++i)
73 assert(*i == j);
74 }
75 {
76 typedef int V;
77 V ar[] =
78 {
79 1,
80 1,
81 1,
82 2,
83 2,
84 2,
85 3,
86 3,
87 3,
88 4,
89 4,
90 4,
91 5,
92 5,
93 5,
94 6,
95 6,
96 6,
97 7,
98 7,
99 7,
100 8,
101 8,
102 8
103 };
104 const std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
105 assert(std::distance(m.begin(), m.end()) == m.size());
106 assert(std::distance(m.cbegin(), m.cend()) == m.size());
107 assert(std::distance(m.rbegin(), m.rend()) == m.size());
108 assert(std::distance(m.crbegin(), m.crend()) == m.size());
109 std::set<int>::const_iterator i;
110 i = m.begin();
111 for (int j = 1; j <= m.size(); ++j, ++i)
112 assert(*i == j);
113 }
114 #if __cplusplus >= 201103L
115 {
116 typedef int V;
117 V ar[] =
118 {
119 1,
120 1,
121 1,
122 2,
123 2,
124 2,
125 3,
126 3,
127 3,
128 4,
129 4,
130 4,
131 5,
132 5,
133 5,
134 6,
135 6,
136 6,
137 7,
138 7,
139 7,
140 8,
141 8,
142 8
143 };
144 std::set<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
145 assert(std::distance(m.begin(), m.end()) == m.size());
146 assert(std::distance(m.rbegin(), m.rend()) == m.size());
147 std::set<int, std::less<int>, min_allocator<int>>::iterator i;
148 i = m.begin();
149 std::set<int, std::less<int>, min_allocator<int>>::const_iterator k = i;
150 assert(i == k);
151 for (int j = 1; j <= m.size(); ++j, ++i)
152 assert(*i == j);
153 }
154 {
155 typedef int V;
156 V ar[] =
157 {
158 1,
159 1,
160 1,
161 2,
162 2,
163 2,
164 3,
165 3,
166 3,
167 4,
168 4,
169 4,
170 5,
171 5,
172 5,
173 6,
174 6,
175 6,
176 7,
177 7,
178 7,
179 8,
180 8,
181 8
182 };
183 const std::set<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
184 assert(std::distance(m.begin(), m.end()) == m.size());
185 assert(std::distance(m.cbegin(), m.cend()) == m.size());
186 assert(std::distance(m.rbegin(), m.rend()) == m.size());
187 assert(std::distance(m.crbegin(), m.crend()) == m.size());
188 std::set<int, std::less<int>, min_allocator<int>>::const_iterator i;
189 i = m.begin();
190 for (int j = 1; j <= m.size(); ++j, ++i)
191 assert(*i == j);
192 }
193 #endif
194 #if _LIBCPP_STD_VER > 11
195 { // N3644 testing
196 typedef std::set<int> C;
197 C::iterator ii1{}, ii2{};
198 C::iterator ii4 = ii1;
199 C::const_iterator cii{};
200 assert ( ii1 == ii2 );
201 assert ( ii1 == ii4 );
202
203 assert (!(ii1 != ii2 ));
204
205 assert ( (ii1 == cii ));
206 assert ( (cii == ii1 ));
207 assert (!(ii1 != cii ));
208 assert (!(cii != ii1 ));
209 }
210 #endif
211 }
212