[VPlan] Add and use debug location for VPScalarCastRecipe.
[llvm-project.git] / libcxx / test / std / containers / sequences / vector.bool / iterators.pass.cpp
blob1e4877e8d24430d1764bc8090f2d25393b423f54
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 // 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;
18 #include <vector>
19 #include <cassert>
20 #include <iterator>
22 #include "test_macros.h"
23 #include "min_allocator.h"
25 TEST_CONSTEXPR_CXX20 bool tests()
27 using IterRefT = std::iterator_traits<std::vector<bool>::iterator>::reference;
28 ASSERT_SAME_TYPE(IterRefT, std::vector<bool>::reference);
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
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);
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);
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());
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;
72 #if TEST_STD_VER >= 11
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);
81 assert(i == j);
82 assert(!(i != j));
84 assert(!(i < j));
85 assert((i <= j));
87 assert(!(i > j));
88 assert((i >= j));
90 # if TEST_STD_VER >= 20
91 // P1614 + LWG3352
92 std::same_as<std::strong_ordering> decltype(auto) r = i <=> j;
93 assert(r == std::strong_ordering::equal);
94 # endif
97 typedef bool T;
98 typedef std::vector<T, min_allocator<T>> C;
99 const C c;
100 C::const_iterator i = c.begin();
101 C::const_iterator j = c.end();
102 assert(std::distance(i, j) == 0);
104 assert(i == j);
105 assert(!(i != j));
107 assert(!(i < j));
108 assert((i <= j));
110 assert(!(i > j));
111 assert((i >= j));
113 # if TEST_STD_VER >= 20
114 // P1614 + LWG3352
115 std::same_as<std::strong_ordering> decltype(auto) r = i <=> j;
116 assert(r == std::strong_ordering::equal);
117 # endif
120 typedef bool T;
121 typedef std::vector<T, min_allocator<T>> C;
122 C c;
123 C::const_iterator i = c.cbegin();
124 C::const_iterator j = c.cend();
125 assert(std::distance(i, j) == 0);
126 assert(i == j);
127 assert(i == c.end());
130 typedef bool T;
131 typedef std::vector<T, min_allocator<T>> C;
132 C::iterator i;
133 C::const_iterator j;
134 (void) i;
135 (void) j;
137 #endif
138 #if TEST_STD_VER > 11
139 { // N3644 testing
140 std::vector<bool>::iterator ii1{}, ii2{};
141 std::vector<bool>::iterator ii4 = ii1;
142 std::vector<bool>::const_iterator cii{};
143 assert ( ii1 == ii2 );
144 assert ( ii1 == ii4 );
146 assert (!(ii1 != ii2 ));
148 assert ( (ii1 == cii ));
149 assert ( (cii == ii1 ));
150 assert (!(ii1 != cii ));
151 assert (!(cii != ii1 ));
152 assert (!(ii1 < cii ));
153 assert (!(cii < ii1 ));
154 assert ( (ii1 <= cii ));
155 assert ( (cii <= ii1 ));
156 assert (!(ii1 > cii ));
157 assert (!(cii > ii1 ));
158 assert ( (ii1 >= cii ));
159 assert ( (cii >= ii1 ));
160 assert (cii - ii1 == 0);
161 assert (ii1 - cii == 0);
163 # if TEST_STD_VER >= 20
164 // P1614 + LWG3352
165 std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2;
166 assert(r1 == std::strong_ordering::equal);
168 std::same_as<std::strong_ordering> decltype(auto) r2 = cii <=> ii2;
169 assert(r2 == std::strong_ordering::equal);
170 # endif // TEST_STD_VER > 20
172 #endif
174 return true;
177 int main(int, char**)
179 tests();
180 #if TEST_STD_VER > 17
181 static_assert(tests());
182 #endif
183 return 0;