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 // iterator begin() noexcept; // constexpr in C++17
12 // const_iterator begin() const noexcept; // constexpr in C++17
13 // iterator end() noexcept; // constexpr in C++17
14 // const_iterator end() const noexcept; // constexpr in C++17
16 // reverse_iterator rbegin() noexcept; // constexpr in C++17
17 // const_reverse_iterator rbegin() const noexcept; // constexpr in C++17
18 // reverse_iterator rend() noexcept; // constexpr in C++17
19 // const_reverse_iterator rend() const noexcept; // constexpr in C++17
21 // const_iterator cbegin() const noexcept; // constexpr in C++17
22 // const_iterator cend() const noexcept; // constexpr in C++17
23 // const_reverse_iterator crbegin() const noexcept; // constexpr in C++17
24 // const_reverse_iterator crend() const noexcept; // constexpr in C++17
30 #include "test_macros.h"
33 TEST_CONSTEXPR
NoDefault(int) { }
37 TEST_CONSTEXPR_CXX17
void check_noexcept(T
& c
) {
38 ASSERT_NOEXCEPT(c
.begin());
39 ASSERT_NOEXCEPT(c
.end());
40 ASSERT_NOEXCEPT(c
.cbegin());
41 ASSERT_NOEXCEPT(c
.cend());
42 ASSERT_NOEXCEPT(c
.rbegin());
43 ASSERT_NOEXCEPT(c
.rend());
44 ASSERT_NOEXCEPT(c
.crbegin());
45 ASSERT_NOEXCEPT(c
.crend());
47 const T
& cc
= c
; (void)cc
;
48 ASSERT_NOEXCEPT(cc
.begin());
49 ASSERT_NOEXCEPT(cc
.end());
50 ASSERT_NOEXCEPT(cc
.rbegin());
51 ASSERT_NOEXCEPT(cc
.rend());
54 TEST_CONSTEXPR_CXX17
bool tests()
57 typedef std::array
<int, 5> C
;
59 check_noexcept(array
);
60 typename
C::iterator i
= array
.begin();
61 typename
C::const_iterator j
= array
.cbegin();
65 typedef std::array
<int, 0> C
;
67 check_noexcept(array
);
68 typename
C::iterator i
= array
.begin();
69 typename
C::const_iterator j
= array
.cbegin();
74 typedef std::array
<int, 0> C
;
76 check_noexcept(array
);
77 typename
C::iterator i
= array
.begin();
78 typename
C::const_iterator j
= array
.cbegin();
79 assert(i
== array
.end());
80 assert(j
== array
.cend());
83 typedef std::array
<int, 1> C
;
85 check_noexcept(array
);
86 typename
C::iterator i
= array
.begin();
88 assert(&*i
== array
.data());
90 assert(array
[0] == 99);
93 typedef std::array
<int, 2> C
;
95 check_noexcept(array
);
96 typename
C::iterator i
= array
.begin();
98 assert(&*i
== array
.data());
100 assert(array
[0] == 99);
101 assert(array
[1] == 2);
104 typedef std::array
<double, 3> C
;
105 C array
= {1, 2, 3.5};
106 check_noexcept(array
);
107 typename
C::iterator i
= array
.begin();
109 assert(&*i
== array
.data());
111 assert(array
[0] == 5.5);
112 assert(array
[1] == 2.0);
115 typedef std::array
<NoDefault
, 0> C
;
117 typename
C::iterator ib
= array
.begin();
118 typename
C::iterator ie
= array
.end();
122 #if TEST_STD_VER >= 14
125 typedef std::array
<int, 5> C
;
126 C::iterator ii1
{}, ii2
{};
127 C::iterator ii4
= ii1
;
128 C::const_iterator cii
{};
133 assert(!(ii1
!= ii2
));
134 assert(!(ii1
!= cii
));
138 assert(c
.begin() == std::begin(c
));
139 assert(c
.cbegin() == std::cbegin(c
));
140 assert(c
.rbegin() == std::rbegin(c
));
141 assert(c
.crbegin() == std::crbegin(c
));
142 assert(c
.end() == std::end(c
));
143 assert(c
.cend() == std::cend(c
));
144 assert(c
.rend() == std::rend(c
));
145 assert(c
.crend() == std::crend(c
));
147 assert(std::begin(c
) != std::end(c
));
148 assert(std::rbegin(c
) != std::rend(c
));
149 assert(std::cbegin(c
) != std::cend(c
));
150 assert(std::crbegin(c
) != std::crend(c
));
152 # if TEST_STD_VER >= 20
154 std::same_as
<std::strong_ordering
> decltype(auto) r1
= ii1
<=> ii2
;
155 assert(r1
== std::strong_ordering::equal
);
157 std::same_as
<std::strong_ordering
> decltype(auto) r2
= cii
<=> ii2
;
158 assert(r2
== std::strong_ordering::equal
);
162 typedef std::array
<int, 0> C
;
163 C::iterator ii1
{}, ii2
{};
164 C::iterator ii4
= ii1
;
165 C::const_iterator cii
{};
169 assert(!(ii1
!= ii2
));
171 assert( (ii1
== cii
));
172 assert( (cii
== ii1
));
173 assert(!(ii1
!= cii
));
174 assert(!(cii
!= ii1
));
175 assert(!(ii1
< cii
));
176 assert(!(cii
< ii1
));
177 assert( (ii1
<= cii
));
178 assert( (cii
<= ii1
));
179 assert(!(ii1
> cii
));
180 assert(!(cii
> ii1
));
181 assert( (ii1
>= cii
));
182 assert( (cii
>= ii1
));
183 assert(cii
- ii1
== 0);
184 assert(ii1
- cii
== 0);
188 assert(c
.begin() == std::begin(c
));
189 assert(c
.cbegin() == std::cbegin(c
));
190 assert(c
.rbegin() == std::rbegin(c
));
191 assert(c
.crbegin() == std::crbegin(c
));
192 assert(c
.end() == std::end(c
));
193 assert(c
.cend() == std::cend(c
));
194 assert(c
.rend() == std::rend(c
));
195 assert(c
.crend() == std::crend(c
));
197 assert(std::begin(c
) == std::end(c
));
198 assert(std::rbegin(c
) == std::rend(c
));
199 assert(std::cbegin(c
) == std::cend(c
));
200 assert(std::crbegin(c
) == std::crend(c
));
202 # if TEST_STD_VER >= 20
204 std::same_as
<std::strong_ordering
> decltype(auto) r1
= ii1
<=> ii2
;
205 assert(r1
== std::strong_ordering::equal
);
207 std::same_as
<std::strong_ordering
> decltype(auto) r2
= cii
<=> ii2
;
208 assert(r2
== std::strong_ordering::equal
);
216 int main(int, char**)
219 #if TEST_STD_VER >= 17
220 static_assert(tests(), "");