blob: d1f0ecfd6aa06b7db2e401ead5aa9fae147ae3b8 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
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;
Howard Hinnant6046ace2010-08-22 00:15:28 +000018//
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000019// reverse_iterator rbegin();
20// const_reverse_iterator rbegin() const;
21// reverse_iterator rend();
22// const_reverse_iterator rend() const;
Howard Hinnant6046ace2010-08-22 00:15:28 +000023//
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000024// 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
Marshall Clow061d0cc2013-11-26 20:58:02 +000032#include "min_allocator.h"
Howard Hinnant70342b92013-06-19 21:29:40 +000033
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034int 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());
Howard Hinnant211f0ee2011-01-28 23:46:28 +000068 std::multiset<int>::iterator i;
69 i = m.begin();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070 std::multiset<int>::const_iterator k = i;
71 assert(i == k);
72 for (int j = 1; j <= 8; ++j)
Dan Albert1d4a1ed2016-05-25 22:36:09 -070073 for (int k = 0; k < 3; ++k, ++i)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000074 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());
Howard Hinnant70342b92013-06-19 21:29:40 +0000110 std::multiset<int>::const_iterator i;
Howard Hinnant211f0ee2011-01-28 23:46:28 +0000111 i = m.begin();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000112 for (int j = 1; j <= 8; ++j)
113 for (int k = 0; k < 3; ++k, ++i)
114 assert(*i == j);
115 }
Howard Hinnant70342b92013-06-19 21:29:40 +0000116#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)
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700154 for (int k = 0; k < 3; ++k, ++i)
Howard Hinnant70342b92013-06-19 21:29:40 +0000155 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
Marshall Clow051c8482013-08-08 21:52:50 +0000198#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 );
Marshall Clow051c8482013-08-08 21:52:50 +0000206
Marshall Clow179e9452014-03-10 19:18:49 +0000207 assert (!(ii1 != ii2 ));
208
209 assert ( (ii1 == cii ));
210 assert ( (cii == ii1 ));
211 assert (!(ii1 != cii ));
212 assert (!(cii != ii1 ));
Marshall Clow051c8482013-08-08 21:52:50 +0000213 }
214#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215}