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