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