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::map
<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::map
<int, double>::iterator i
;
71 std::map
<int, double>::const_iterator k
= i
;
73 for (int j
= 1; static_cast<std::size_t>(j
) <= m
.size(); ++j
, ++i
)
75 assert(i
->first
== j
);
76 assert(i
->second
== 1);
78 assert(i
->second
== 2.5);
81 for (int j
= m
.size(); j
>= 1; --j
)
84 assert(i
->first
== j
);
85 assert(i
->second
== 2.5);
87 assert(i
->second
== 1);
89 assert(i
== m
.begin());
92 typedef std::pair
<const int, double> V
;
120 const std::map
<int, double> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
121 assert(static_cast<std::size_t>(std::distance(m
.begin(), m
.end())) == m
.size());
122 assert(static_cast<std::size_t>(std::distance(m
.cbegin(), m
.cend())) == m
.size());
123 assert(static_cast<std::size_t>(std::distance(m
.rbegin(), m
.rend())) == m
.size());
124 assert(static_cast<std::size_t>(std::distance(m
.crbegin(), m
.crend())) == m
.size());
125 std::map
<int, double>::const_iterator i
;
127 for (int j
= 1; static_cast<std::size_t>(j
) <= m
.size(); ++j
, ++i
)
129 assert(i
->first
== j
);
130 assert(i
->second
== 1);
132 assert(i
== m
.end());
133 for (int j
= m
.size(); j
>= 1; --j
)
136 assert(i
->first
== j
);
137 assert(i
->second
== 1);
139 assert(i
== m
.begin());
141 #if TEST_STD_VER >= 11
143 typedef std::pair
<const int, double> V
;
171 std::map
<int, double, std::less
<int>, min_allocator
<V
>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
172 assert(static_cast<std::size_t>(std::distance(m
.begin(), m
.end())) == m
.size());
173 assert(static_cast<std::size_t>(std::distance(m
.rbegin(), m
.rend())) == m
.size());
174 std::map
<int, double, std::less
<int>, min_allocator
<V
>>::iterator i
;
176 std::map
<int, double, std::less
<int>, min_allocator
<V
>>::const_iterator k
= i
;
178 for (int j
= 1; static_cast<std::size_t>(j
) <= m
.size(); ++j
, ++i
)
180 assert(i
->first
== j
);
181 assert(i
->second
== 1);
183 assert(i
->second
== 2.5);
185 assert(i
== m
.end());
186 for (int j
= m
.size(); j
>= 1; --j
)
189 assert(i
->first
== j
);
190 assert(i
->second
== 2.5);
192 assert(i
->second
== 1);
194 assert(i
== m
.begin());
197 typedef std::pair
<const int, double> V
;
225 const std::map
<int, double, std::less
<int>, min_allocator
<V
>> m(ar
, ar
+sizeof(ar
)/sizeof(ar
[0]));
226 assert(static_cast<std::size_t>(std::distance(m
.begin(), m
.end())) == m
.size());
227 assert(static_cast<std::size_t>(std::distance(m
.cbegin(), m
.cend())) == m
.size());
228 assert(static_cast<std::size_t>(std::distance(m
.rbegin(), m
.rend())) == m
.size());
229 assert(static_cast<std::size_t>(std::distance(m
.crbegin(), m
.crend())) == m
.size());
230 std::map
<int, double, std::less
<int>, min_allocator
<V
>>::const_iterator i
;
232 for (int j
= 1; static_cast<std::size_t>(j
) <= m
.size(); ++j
, ++i
)
234 assert(i
->first
== j
);
235 assert(i
->second
== 1);
237 assert(i
== m
.end());
238 for (int j
= m
.size(); j
>= 1; --j
)
241 assert(i
->first
== j
);
242 assert(i
->second
== 1);
244 assert(i
== m
.begin());
247 #if TEST_STD_VER > 11
249 typedef std::map
<int, double> C
;
250 C::iterator ii1
{}, ii2
{};
251 C::iterator ii4
= ii1
;
252 C::const_iterator cii
{};
253 assert ( ii1
== ii2
);
254 assert ( ii1
== ii4
);
256 assert (!(ii1
!= ii2
));
258 assert ( (ii1
== cii
));
259 assert ( (cii
== ii1
));
260 assert (!(ii1
!= cii
));
261 assert (!(cii
!= ii1
));