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 | //===----------------------------------------------------------------------===// |
8 | |
9 | // <vector> |
10 | |
11 | // iterator begin(); |
12 | // iterator end(); |
13 | // const_iterator begin() const; |
14 | // const_iterator end() const; |
15 | // const_iterator cbegin() const; |
16 | // const_iterator cend() const; |
17 | |
18 | #include <vector> |
19 | #include <cassert> |
20 | #include <iterator> |
21 | |
22 | #include "test_macros.h" |
23 | #include "min_allocator.h" |
24 | |
25 | TEST_CONSTEXPR_CXX20 bool tests() |
26 | { |
27 | using IterRefT = std::iterator_traits<std::vector<bool>::iterator>::reference; |
28 | ASSERT_SAME_TYPE(IterRefT, std::vector<bool>::reference); |
29 | |
30 | using ConstIterRefT = std::iterator_traits<std::vector<bool>::const_iterator>::reference; |
31 | #if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL) |
32 | ASSERT_SAME_TYPE(ConstIterRefT, bool); |
33 | #else |
34 | ASSERT_SAME_TYPE(ConstIterRefT, std::__bit_const_reference<std::vector<bool> >); |
35 | #endif |
36 | { |
37 | typedef bool T; |
38 | typedef std::vector<T> C; |
39 | C c; |
40 | C::iterator i = c.begin(); |
41 | C::iterator j = c.end(); |
42 | assert(std::distance(i, j) == 0); |
43 | assert(i == j); |
44 | } |
45 | { |
46 | typedef bool T; |
47 | typedef std::vector<T> C; |
48 | const C c; |
49 | C::const_iterator i = c.begin(); |
50 | C::const_iterator j = c.end(); |
51 | assert(std::distance(i, j) == 0); |
52 | assert(i == j); |
53 | } |
54 | { |
55 | typedef bool T; |
56 | typedef std::vector<T> C; |
57 | C c; |
58 | C::const_iterator i = c.cbegin(); |
59 | C::const_iterator j = c.cend(); |
60 | assert(std::distance(i, j) == 0); |
61 | assert(i == j); |
62 | assert(i == c.end()); |
63 | } |
64 | { |
65 | typedef bool T; |
66 | typedef std::vector<T> C; |
67 | C::iterator i; |
68 | C::const_iterator j; |
69 | (void) i; |
70 | (void) j; |
71 | } |
72 | #if TEST_STD_VER >= 11 |
73 | { |
74 | typedef bool T; |
75 | typedef std::vector<T, min_allocator<T>> C; |
76 | C c; |
77 | C::iterator i = c.begin(); |
78 | C::iterator j = c.end(); |
79 | assert(std::distance(i, j) == 0); |
80 | assert(i == j); |
81 | } |
82 | { |
83 | typedef bool T; |
84 | typedef std::vector<T, min_allocator<T>> C; |
85 | const C c; |
86 | C::const_iterator i = c.begin(); |
87 | C::const_iterator j = c.end(); |
88 | assert(std::distance(i, j) == 0); |
89 | assert(i == j); |
90 | } |
91 | { |
92 | typedef bool T; |
93 | typedef std::vector<T, min_allocator<T>> C; |
94 | C c; |
95 | C::const_iterator i = c.cbegin(); |
96 | C::const_iterator j = c.cend(); |
97 | assert(std::distance(i, j) == 0); |
98 | assert(i == j); |
99 | assert(i == c.end()); |
100 | } |
101 | { |
102 | typedef bool T; |
103 | typedef std::vector<T, min_allocator<T>> C; |
104 | C::iterator i; |
105 | C::const_iterator j; |
106 | (void) i; |
107 | (void) j; |
108 | } |
109 | #endif |
110 | #if TEST_STD_VER > 11 |
111 | { // N3644 testing |
112 | std::vector<bool>::iterator ii1{}, ii2{}; |
113 | std::vector<bool>::iterator ii4 = ii1; |
114 | std::vector<bool>::const_iterator cii{}; |
115 | assert ( ii1 == ii2 ); |
116 | assert ( ii1 == ii4 ); |
117 | |
118 | assert (!(ii1 != ii2 )); |
119 | |
120 | assert ( (ii1 == cii )); |
121 | assert ( (cii == ii1 )); |
122 | assert (!(ii1 != cii )); |
123 | assert (!(cii != ii1 )); |
124 | assert (!(ii1 < cii )); |
125 | assert (!(cii < ii1 )); |
126 | assert ( (ii1 <= cii )); |
127 | assert ( (cii <= ii1 )); |
128 | assert (!(ii1 > cii )); |
129 | assert (!(cii > ii1 )); |
130 | assert ( (ii1 >= cii )); |
131 | assert ( (cii >= ii1 )); |
132 | assert (cii - ii1 == 0); |
133 | assert (ii1 - cii == 0); |
134 | } |
135 | #endif |
136 | |
137 | return true; |
138 | } |
139 | |
140 | int main(int, char**) |
141 | { |
142 | tests(); |
143 | #if TEST_STD_VER > 17 |
144 | static_assert(tests()); |
145 | #endif |
146 | return 0; |
147 | } |
148 | |