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 //===----------------------------------------------------------------------===//
11 // reverse_iterator rbegin();
12 // reverse_iterator rend();
13 // const_reverse_iterator rbegin() const;
14 // const_reverse_iterator rend() const;
15 // const_reverse_iterator crbegin() const;
16 // const_reverse_iterator crend() const;
22 #include "min_allocator.h"
24 template <class Vector
>
25 TEST_CONSTEXPR_CXX20
void check_vector_reverse_iterators() {
28 assert(vec
.rbegin() == vec
.rend());
29 assert(vec
.crbegin() == vec
.crend());
34 const Vector
& cvec
= vec
;
36 for (int i
= 0; i
< n
; ++i
)
41 for (typename
Vector::const_reverse_iterator it
= vec
.crbegin(); it
!= vec
.crend(); ++it
) {
42 assert(*it
== (n
- iterations
- 1));
45 assert(iterations
== n
);
48 assert(cvec
.rbegin() == vec
.crbegin());
49 assert(cvec
.rend() == vec
.crend());
54 for (typename
Vector::reverse_iterator it
= vec
.rbegin(); it
!= vec
.rend(); ++it
) {
55 assert(*it
== (n
- iterations
- 1));
60 assert(iterations
== n
);
63 assert(std::distance(vec
.rbegin(), vec
.rend()) == n
);
64 assert(std::distance(cvec
.rbegin(), cvec
.rend()) == n
);
65 assert(std::distance(vec
.crbegin(), vec
.crend()) == n
);
66 assert(std::distance(cvec
.crbegin(), cvec
.crend()) == n
);
70 TEST_CONSTEXPR_CXX20
bool test() {
71 check_vector_reverse_iterators
<std::vector
<int> >();
72 #if TEST_STD_VER >= 11
73 check_vector_reverse_iterators
<std::vector
<int, min_allocator
<int> > >();
79 int main(int, char**) {
82 static_assert(test());