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 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
12 // constexpr reverse_iterator rend() const noexcept;
13 // constexpr const_reverse_iterator crend() const noexcept;
19 #include "test_macros.h"
22 constexpr bool testConstexprSpan(Span s
)
25 typename
Span::reverse_iterator e
= s
.rend();
28 ret
= ret
&& (e
== s
.rbegin());
32 ret
= ret
&& (e
!= s
.rbegin());
35 ret
= ret
&& (static_cast<std::size_t>(e
- s
.rbegin()) == s
.size());
40 void testRuntimeSpan(Span s
)
42 typename
Span::reverse_iterator e
= s
.rend();
45 assert(e
== s
.rbegin());
49 assert(e
!= s
.rbegin());
52 assert(static_cast<std::size_t>(e
- s
.rbegin()) == s
.size());
57 bool operator==(A
, A
) {return true;}
59 constexpr int iArr1
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
60 int iArr2
[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
65 static_assert(testConstexprSpan(std::span
<int>()), "");
66 static_assert(testConstexprSpan(std::span
<long>()), "");
67 static_assert(testConstexprSpan(std::span
<double>()), "");
68 static_assert(testConstexprSpan(std::span
<A
>()), "");
69 static_assert(testConstexprSpan(std::span
<std::string
>()), "");
71 static_assert(testConstexprSpan(std::span
<int, 0>()), "");
72 static_assert(testConstexprSpan(std::span
<long, 0>()), "");
73 static_assert(testConstexprSpan(std::span
<double, 0>()), "");
74 static_assert(testConstexprSpan(std::span
<A
, 0>()), "");
75 static_assert(testConstexprSpan(std::span
<std::string
, 0>()), "");
77 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 1)), "");
78 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 2)), "");
79 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 3)), "");
80 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 4)), "");
81 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 5)), "");
84 testRuntimeSpan(std::span
<int> ());
85 testRuntimeSpan(std::span
<long> ());
86 testRuntimeSpan(std::span
<double> ());
87 testRuntimeSpan(std::span
<A
> ());
88 testRuntimeSpan(std::span
<std::string
>());
90 testRuntimeSpan(std::span
<int, 0> ());
91 testRuntimeSpan(std::span
<long, 0> ());
92 testRuntimeSpan(std::span
<double, 0> ());
93 testRuntimeSpan(std::span
<A
, 0> ());
94 testRuntimeSpan(std::span
<std::string
, 0>());
96 testRuntimeSpan(std::span
<int>(iArr2
, 1));
97 testRuntimeSpan(std::span
<int>(iArr2
, 2));
98 testRuntimeSpan(std::span
<int>(iArr2
, 3));
99 testRuntimeSpan(std::span
<int>(iArr2
, 4));
100 testRuntimeSpan(std::span
<int>(iArr2
, 5));
103 testRuntimeSpan(std::span
<std::string
>(&s
, (std::size_t) 0));
104 testRuntimeSpan(std::span
<std::string
>(&s
, 1));