llvm-project
274 строки · 7.9 Кб
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// <map>
10
11// class multimap
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 <map>
29#include <cassert>
30#include <cstddef>
31
32#include "test_macros.h"
33#include "min_allocator.h"
34
35int main(int, char**)
36{
37{
38typedef std::pair<const int, double> V;
39V ar[] =
40{
41V(1, 1),
42V(1, 1.5),
43V(1, 2),
44V(2, 1),
45V(2, 1.5),
46V(2, 2),
47V(3, 1),
48V(3, 1.5),
49V(3, 2),
50V(4, 1),
51V(4, 1.5),
52V(4, 2),
53V(5, 1),
54V(5, 1.5),
55V(5, 2),
56V(6, 1),
57V(6, 1.5),
58V(6, 2),
59V(7, 1),
60V(7, 1.5),
61V(7, 2),
62V(8, 1),
63V(8, 1.5),
64V(8, 2)
65};
66std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
67assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
68assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
69std::multimap<int, double>::iterator i;
70i = m.begin();
71std::multimap<int, double>::const_iterator k = i;
72assert(i == k);
73for (int j = 1; j <= 8; ++j)
74for (double d = 1; d <= 2; d += .5, ++i)
75{
76assert(i->first == j);
77assert(i->second == d);
78i->second = 2.5;
79assert(i->second == 2.5);
80}
81assert(i == m.end());
82for (int j = 8; j >= 1; --j)
83for (double d = 1; d <= 2; d += .5)
84{
85--i;
86assert(i->first == j);
87assert(i->second == 2.5);
88i->second = d;
89assert(i->second == d);
90}
91assert(i == m.begin());
92}
93{
94typedef std::pair<const int, double> V;
95V ar[] =
96{
97V(1, 1),
98V(1, 1.5),
99V(1, 2),
100V(2, 1),
101V(2, 1.5),
102V(2, 2),
103V(3, 1),
104V(3, 1.5),
105V(3, 2),
106V(4, 1),
107V(4, 1.5),
108V(4, 2),
109V(5, 1),
110V(5, 1.5),
111V(5, 2),
112V(6, 1),
113V(6, 1.5),
114V(6, 2),
115V(7, 1),
116V(7, 1.5),
117V(7, 2),
118V(8, 1),
119V(8, 1.5),
120V(8, 2)
121};
122const std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
123assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
124assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
125assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
126assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
127std::multimap<int, double>::const_iterator i;
128i = m.begin();
129for (int j = 1; j <= 8; ++j)
130for (double d = 1; d <= 2; d += .5, ++i)
131{
132assert(i->first == j);
133assert(i->second == d);
134}
135assert(i == m.end());
136for (int j = 8; j >= 1; --j)
137for (double d = 2; d >= 1; d -= .5)
138{
139--i;
140assert(i->first == j);
141assert(i->second == d);
142}
143assert(i == m.begin());
144}
145#if TEST_STD_VER >= 11
146{
147typedef std::pair<const int, double> V;
148V ar[] =
149{
150V(1, 1),
151V(1, 1.5),
152V(1, 2),
153V(2, 1),
154V(2, 1.5),
155V(2, 2),
156V(3, 1),
157V(3, 1.5),
158V(3, 2),
159V(4, 1),
160V(4, 1.5),
161V(4, 2),
162V(5, 1),
163V(5, 1.5),
164V(5, 2),
165V(6, 1),
166V(6, 1.5),
167V(6, 2),
168V(7, 1),
169V(7, 1.5),
170V(7, 2),
171V(8, 1),
172V(8, 1.5),
173V(8, 2)
174};
175std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
176assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
177assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
178std::multimap<int, double, std::less<int>, min_allocator<V>>::iterator i;
179i = m.begin();
180std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator k = i;
181assert(i == k);
182for (int j = 1; j <= 8; ++j)
183for (double d = 1; d <= 2; d += .5, ++i)
184{
185assert(i->first == j);
186assert(i->second == d);
187i->second = 2.5;
188assert(i->second == 2.5);
189}
190assert(i == m.end());
191for (int j = 8; j >= 1; --j)
192for (double d = 1; d <= 2; d += .5)
193{
194--i;
195assert(i->first == j);
196assert(i->second == 2.5);
197i->second = d;
198assert(i->second == d);
199}
200assert(i == m.begin());
201}
202{
203typedef std::pair<const int, double> V;
204V ar[] =
205{
206V(1, 1),
207V(1, 1.5),
208V(1, 2),
209V(2, 1),
210V(2, 1.5),
211V(2, 2),
212V(3, 1),
213V(3, 1.5),
214V(3, 2),
215V(4, 1),
216V(4, 1.5),
217V(4, 2),
218V(5, 1),
219V(5, 1.5),
220V(5, 2),
221V(6, 1),
222V(6, 1.5),
223V(6, 2),
224V(7, 1),
225V(7, 1.5),
226V(7, 2),
227V(8, 1),
228V(8, 1.5),
229V(8, 2)
230};
231const std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
232assert(static_cast<std::size_t>(std::distance(m.begin(), m.end())) == m.size());
233assert(static_cast<std::size_t>(std::distance(m.cbegin(), m.cend())) == m.size());
234assert(static_cast<std::size_t>(std::distance(m.rbegin(), m.rend())) == m.size());
235assert(static_cast<std::size_t>(std::distance(m.crbegin(), m.crend())) == m.size());
236std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator i;
237i = m.begin();
238for (int j = 1; j <= 8; ++j)
239for (double d = 1; d <= 2; d += .5, ++i)
240{
241assert(i->first == j);
242assert(i->second == d);
243}
244assert(i == m.end());
245for (int j = 8; j >= 1; --j)
246for (double d = 2; d >= 1; d -= .5)
247{
248--i;
249assert(i->first == j);
250assert(i->second == d);
251}
252assert(i == m.begin());
253}
254#endif
255#if TEST_STD_VER > 11
256{ // N3644 testing
257typedef std::multimap<int, double> C;
258C::iterator ii1{}, ii2{};
259C::iterator ii4 = ii1;
260C::const_iterator cii{};
261assert ( ii1 == ii2 );
262assert ( ii1 == ii4 );
263
264assert (!(ii1 != ii2 ));
265
266assert ( (ii1 == cii ));
267assert ( (cii == ii1 ));
268assert (!(ii1 != cii ));
269assert (!(cii != ii1 ));
270}
271#endif
272
273return 0;
274}
275