Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / containers / sequences / vector / reverse_iterators.pass.cpp
blob1591f912f3372c91aef973be226984592e15b84e
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 //===----------------------------------------------------------------------===//
9 // <vector>
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;
18 #include <vector>
19 #include <cassert>
20 #include <iterator>
22 #include "min_allocator.h"
24 template <class Vector>
25 TEST_CONSTEXPR_CXX20 void check_vector_reverse_iterators() {
27 Vector vec;
28 assert(vec.rbegin() == vec.rend());
29 assert(vec.crbegin() == vec.crend());
32 const int n = 10;
33 Vector vec;
34 const Vector& cvec = vec;
35 vec.reserve(n);
36 for (int i = 0; i < n; ++i)
37 vec.push_back(i);
39 int iterations = 0;
41 for (typename Vector::const_reverse_iterator it = vec.crbegin(); it != vec.crend(); ++it) {
42 assert(*it == (n - iterations - 1));
43 ++iterations;
45 assert(iterations == n);
48 assert(cvec.rbegin() == vec.crbegin());
49 assert(cvec.rend() == vec.crend());
52 int iterations = 0;
54 for (typename Vector::reverse_iterator it = vec.rbegin(); it != vec.rend(); ++it) {
55 assert(*it == (n - iterations - 1));
56 *it = 40;
57 assert(*it == 40);
58 ++iterations;
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> > >();
74 #endif
76 return true;
79 int main(int, char**) {
80 test();
81 #if TEST_STD_VER > 17
82 static_assert(test());
83 #endif
85 return 0;