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