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