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