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
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::multiset<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::multiset<int>::iterator i;
69 i = m.begin();
70 std::multiset<int>::const_iterator k = i;
71 assert(i == k);
72 for (int j = 1; j <= 8; ++j)
73 for (int k = 0; k < 3; ++k, ++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::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
106 assert(std::distance(m.begin(), m.end()) == m.size());
107 assert(std::distance(m.cbegin(), m.cend()) == m.size());
108 assert(std::distance(m.rbegin(), m.rend()) == m.size());
109 assert(std::distance(m.crbegin(), m.crend()) == m.size());
110 std::multiset<int>::const_iterator i;
111 i = m.begin();
112 for (int j = 1; j <= 8; ++j)
113 for (int k = 0; k < 3; ++k, ++i)
114 assert(*i == j);
115 }
116 #if __cplusplus >= 201103L
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::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
147 assert(std::distance(m.begin(), m.end()) == m.size());
148 assert(std::distance(m.rbegin(), m.rend()) == m.size());
149 std::multiset<int, std::less<int>, min_allocator<int>>::iterator i;
150 i = m.begin();
151 std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator k = i;
152 assert(i == k);
153 for (int j = 1; j <= 8; ++j)
154 for (int k = 0; k < 3; ++k, ++i)
155 assert(*i == j);
156 }
157 {
158 typedef int V;
159 V ar[] =
160 {
161 1,
162 1,
163 1,
164 2,
165 2,
166 2,
167 3,
168 3,
169 3,
170 4,
171 4,
172 4,
173 5,
174 5,
175 5,
176 6,
177 6,
178 6,
179 7,
180 7,
181 7,
182 8,
183 8,
184 8
185 };
186 const std::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
187 assert(std::distance(m.begin(), m.end()) == m.size());
188 assert(std::distance(m.cbegin(), m.cend()) == m.size());
189 assert(std::distance(m.rbegin(), m.rend()) == m.size());
190 assert(std::distance(m.crbegin(), m.crend()) == m.size());
191 std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator i;
192 i = m.begin();
193 for (int j = 1; j <= 8; ++j)
194 for (int k = 0; k < 3; ++k, ++i)
195 assert(*i == j);
196 }
197 #endif
198 #if _LIBCPP_STD_VER > 11
199 { // N3644 testing
200 typedef std::multiset<int> C;
201 C::iterator ii1{}, ii2{};
202 C::iterator ii4 = ii1;
203 C::const_iterator cii{};
204 assert ( ii1 == ii2 );
205 assert ( ii1 == ii4 );
206
207 assert (!(ii1 != ii2 ));
208
209 assert ( (ii1 == cii ));
210 assert ( (cii == ii1 ));
211 assert (!(ii1 != cii ));
212 assert (!(cii != ii1 ));
213 }
214 #endif
215 }
216