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 //===----------------------------------------------------------------------===//
13 // const_iterator begin() const;
14 // const_iterator end() const;
15 // const_iterator cbegin() const;
16 // const_iterator cend() const;
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);
34 ASSERT_SAME_TYPE(ConstIterRefT
, std::__bit_const_reference
<std::vector
<bool> >);
38 typedef std::vector
<T
> C
;
40 C::iterator i
= c
.begin();
41 C::iterator j
= c
.end();
42 assert(std::distance(i
, j
) == 0);
47 typedef std::vector
<T
> C
;
49 C::const_iterator i
= c
.begin();
50 C::const_iterator j
= c
.end();
51 assert(std::distance(i
, j
) == 0);
56 typedef std::vector
<T
> C
;
58 C::const_iterator i
= c
.cbegin();
59 C::const_iterator j
= c
.cend();
60 assert(std::distance(i
, j
) == 0);
66 typedef std::vector
<T
> C
;
72 #if TEST_STD_VER >= 11
75 typedef std::vector
<T
, min_allocator
<T
>> C
;
77 C::iterator i
= c
.begin();
78 C::iterator j
= c
.end();
79 assert(std::distance(i
, j
) == 0);
90 # if TEST_STD_VER >= 20
92 std::same_as
<std::strong_ordering
> decltype(auto) r
= i
<=> j
;
93 assert(r
== std::strong_ordering::equal
);
98 typedef std::vector
<T
, min_allocator
<T
>> C
;
100 C::const_iterator i
= c
.begin();
101 C::const_iterator j
= c
.end();
102 assert(std::distance(i
, j
) == 0);
113 # if TEST_STD_VER >= 20
115 std::same_as
<std::strong_ordering
> decltype(auto) r
= i
<=> j
;
116 assert(r
== std::strong_ordering::equal
);
121 typedef std::vector
<T
, min_allocator
<T
>> C
;
123 C::const_iterator i
= c
.cbegin();
124 C::const_iterator j
= c
.cend();
125 assert(std::distance(i
, j
) == 0);
127 assert(i
== c
.end());
131 typedef std::vector
<T
, min_allocator
<T
>> C
;
138 #if TEST_STD_VER > 11
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
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
177 int main(int, char**)
180 #if TEST_STD_VER > 17
181 static_assert(tests());