1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
14 // const_iterator begin() const;
16 // const_iterator end() const;
18 // reverse_iterator rbegin();
19 // const_reverse_iterator rbegin() const;
20 // reverse_iterator rend();
21 // const_reverse_iterator rend() const;
23 // const_iterator cbegin() const;
24 // const_iterator cend() const;
25 // const_reverse_iterator crbegin() const;
26 // const_reverse_iterator crend() const;
32 #include "test_macros.h"
33 #include "min_allocator.h"
38 typedef std::pair
<const int, double> V
;
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
;
71 std::multimap
<int, double>::const_iterator k
= i
;
73 for (int j
= 1; j
<= 8; ++j
)
74 for (double d
= 1; d
<= 2; d
+= .5, ++i
)
76 assert(i
->first
== j
);
77 assert(i
->second
== d
);
79 assert(i
->second
== 2.5);
82 for (int j
= 8; j
>= 1; --j
)
83 for (double d
= 1; d
<= 2; d
+= .5)
86 assert(i
->first
== j
);
87 assert(i
->second
== 2.5);
89 assert(i
->second
== d
);
91 assert(i
== m
.begin());
94 typedef std::pair
<const int, double> V
;
122 const std::multimap
<int, double> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
123 assert(static_cast<std::size_t>(std::distance(m
.begin(), m
.end())) == m
.size());
124 assert(static_cast<std::size_t>(std::distance(m
.cbegin(), m
.cend())) == m
.size());
125 assert(static_cast<std::size_t>(std::distance(m
.rbegin(), m
.rend())) == m
.size());
126 assert(static_cast<std::size_t>(std::distance(m
.crbegin(), m
.crend())) == m
.size());
127 std::multimap
<int, double>::const_iterator i
;
129 for (int j
= 1; j
<= 8; ++j
)
130 for (double d
= 1; d
<= 2; d
+= .5, ++i
)
132 assert(i
->first
== j
);
133 assert(i
->second
== d
);
135 assert(i
== m
.end());
136 for (int j
= 8; j
>= 1; --j
)
137 for (double d
= 2; d
>= 1; d
-= .5)
140 assert(i
->first
== j
);
141 assert(i
->second
== d
);
143 assert(i
== m
.begin());
145 #if TEST_STD_VER >= 11
147 typedef std::pair
<const int, double> V
;
175 std::multimap
<int, double, std::less
<int>, min_allocator
<V
>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
176 assert(static_cast<std::size_t>(std::distance(m
.begin(), m
.end())) == m
.size());
177 assert(static_cast<std::size_t>(std::distance(m
.rbegin(), m
.rend())) == m
.size());
178 std::multimap
<int, double, std::less
<int>, min_allocator
<V
>>::iterator i
;
180 std::multimap
<int, double, std::less
<int>, min_allocator
<V
>>::const_iterator k
= i
;
182 for (int j
= 1; j
<= 8; ++j
)
183 for (double d
= 1; d
<= 2; d
+= .5, ++i
)
185 assert(i
->first
== j
);
186 assert(i
->second
== d
);
188 assert(i
->second
== 2.5);
190 assert(i
== m
.end());
191 for (int j
= 8; j
>= 1; --j
)
192 for (double d
= 1; d
<= 2; d
+= .5)
195 assert(i
->first
== j
);
196 assert(i
->second
== 2.5);
198 assert(i
->second
== d
);
200 assert(i
== m
.begin());
203 typedef std::pair
<const int, double> V
;
231 const std::multimap
<int, double, std::less
<int>, min_allocator
<V
>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
232 assert(static_cast<std::size_t>(std::distance(m
.begin(), m
.end())) == m
.size());
233 assert(static_cast<std::size_t>(std::distance(m
.cbegin(), m
.cend())) == m
.size());
234 assert(static_cast<std::size_t>(std::distance(m
.rbegin(), m
.rend())) == m
.size());
235 assert(static_cast<std::size_t>(std::distance(m
.crbegin(), m
.crend())) == m
.size());
236 std::multimap
<int, double, std::less
<int>, min_allocator
<V
>>::const_iterator i
;
238 for (int j
= 1; j
<= 8; ++j
)
239 for (double d
= 1; d
<= 2; d
+= .5, ++i
)
241 assert(i
->first
== j
);
242 assert(i
->second
== d
);
244 assert(i
== m
.end());
245 for (int j
= 8; j
>= 1; --j
)
246 for (double d
= 2; d
>= 1; d
-= .5)
249 assert(i
->first
== j
);
250 assert(i
->second
== d
);
252 assert(i
== m
.begin());
255 #if TEST_STD_VER > 11
257 typedef std::multimap
<int, double> C
;
258 C::iterator ii1
{}, ii2
{};
259 C::iterator ii4
= ii1
;
260 C::const_iterator cii
{};
261 assert ( ii1
== ii2
);
262 assert ( ii1
== ii4
);
264 assert (!(ii1
!= ii2
));
266 assert ( (ii1
== cii
));
267 assert ( (cii
== ii1
));
268 assert (!(ii1
!= cii
));
269 assert (!(cii
!= ii1
));