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 multiset
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
35int 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::multiset<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::multiset<int>::iterator i;
70 i = m.begin();
71 std::multiset<int>::const_iterator k = i;
72 assert(i == k);
73 for (int j = 1; j <= 8; ++j)
74 for (int n = 0; n < 3; ++n, ++i)
75 assert(*i == j);
76 assert(i == m.end());
77 for (int j = 8; j >= 1; --j)
78 for (int n = 0; n < 3; ++n) {
79 --i;
80 assert(*i == j);
81 }
82 assert(i == m.begin());
83 }
84 {
85 typedef int V;
86 V ar[] =
87 {
88 1,
89 1,
90 1,
91 2,
92 2,
93 2,
94 3,
95 3,
96 3,
97 4,
98 4,
99 4,
100 5,
101 5,
102 5,
103 6,
104 6,
105 6,
106 7,
107 7,
108 7,
109 8,
110 8,
111 8
112 };
113 const std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
114 assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
115 assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
116 assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
117 assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
118 std::multiset<int>::const_iterator i;
119 i = m.begin();
120 for (int j = 1; j <= 8; ++j)
121 for (int k = 0; k < 3; ++k, ++i)
122 assert(*i == j);
123 assert(i == m.end());
124 for (int j = 8; j >= 1; --j)
125 for (int k = 0; k < 3; ++k) {
126 --i;
127 assert(*i == j);
128 }
129 assert(i == m.begin());
130 }
131#if TEST_STD_VER >= 11
132 {
133 typedef int V;
134 V ar[] =
135 {
136 1,
137 1,
138 1,
139 2,
140 2,
141 2,
142 3,
143 3,
144 3,
145 4,
146 4,
147 4,
148 5,
149 5,
150 5,
151 6,
152 6,
153 6,
154 7,
155 7,
156 7,
157 8,
158 8,
159 8
160 };
161 std::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
162 assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
163 assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
164 std::multiset<int, std::less<int>, min_allocator<int>>::iterator i;
165 i = m.begin();
166 std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator k = i;
167 assert(i == k);
168 for (int j = 1; j <= 8; ++j)
169 for (int n = 0; n < 3; ++n, ++i)
170 assert(*i == j);
171 assert(i == m.end());
172 for (int j = 8; j >= 1; --j)
173 for (int n = 0; n < 3; ++n) {
174 --i;
175 assert(*i == j);
176 }
177 assert(i == m.begin());
178 }
179 {
180 typedef int V;
181 V ar[] =
182 {
183 1,
184 1,
185 1,
186 2,
187 2,
188 2,
189 3,
190 3,
191 3,
192 4,
193 4,
194 4,
195 5,
196 5,
197 5,
198 6,
199 6,
200 6,
201 7,
202 7,
203 7,
204 8,
205 8,
206 8
207 };
208 const std::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
209 assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
210 assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
211 assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
212 assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
213 std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator i;
214 i = m.begin();
215 for (int j = 1; j <= 8; ++j)
216 for (int k = 0; k < 3; ++k, ++i)
217 assert(*i == j);
218 assert(i == m.end());
219 for (int j = 8; j >= 1; --j)
220 for (int k = 0; k < 3; ++k) {
221 --i;
222 assert(*i == j);
223 }
224 assert(i == m.begin());
225 }
226#endif
227#if TEST_STD_VER > 11
228 { // N3644 testing
229 typedef std::multiset<int> C;
230 C::iterator ii1{}, ii2{};
231 C::iterator ii4 = ii1;
232 C::const_iterator cii{};
233 assert ( ii1 == ii2 );
234 assert ( ii1 == ii4 );
235
236 assert (!(ii1 != ii2 ));
237
238 assert ( (ii1 == cii ));
239 assert ( (cii == ii1 ));
240 assert (!(ii1 != cii ));
241 assert (!(cii != ii1 ));
242 }
243#endif
244
245 return 0;
246}
247

source code of libcxx/test/std/containers/associative/multiset/iterator.pass.cpp