2 //===------------------------------ span ---------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===---------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
13 // constexpr pointer data() const noexcept;
21 #include "test_macros.h"
24 template <typename Span
>
25 constexpr bool testConstexprSpan(Span sp
, typename
Span::pointer ptr
)
27 ASSERT_NOEXCEPT(sp
.data());
28 return sp
.data() == ptr
;
32 template <typename Span
>
33 void testRuntimeSpan(Span sp
, typename
Span::pointer ptr
)
35 ASSERT_NOEXCEPT(sp
.data());
36 assert(sp
.data() == ptr
);
40 constexpr int iArr1
[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
41 int iArr2
[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
47 static_assert(testConstexprSpan(std::span
<int>(), nullptr), "");
48 static_assert(testConstexprSpan(std::span
<long>(), nullptr), "");
49 static_assert(testConstexprSpan(std::span
<double>(), nullptr), "");
50 static_assert(testConstexprSpan(std::span
<A
>(), nullptr), "");
51 static_assert(testConstexprSpan(std::span
<std::string
>(), nullptr), "");
53 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 1), iArr1
), "");
54 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 2), iArr1
), "");
55 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 3), iArr1
), "");
56 static_assert(testConstexprSpan(std::span
<const int>(iArr1
, 4), iArr1
), "");
58 static_assert(testConstexprSpan(std::span
<const int>(iArr1
+ 1, 1), iArr1
+ 1), "");
59 static_assert(testConstexprSpan(std::span
<const int>(iArr1
+ 2, 2), iArr1
+ 2), "");
60 static_assert(testConstexprSpan(std::span
<const int>(iArr1
+ 3, 3), iArr1
+ 3), "");
61 static_assert(testConstexprSpan(std::span
<const int>(iArr1
+ 4, 4), iArr1
+ 4), "");
64 static_assert(testConstexprSpan(std::span
<int, 0>(), nullptr), "");
65 static_assert(testConstexprSpan(std::span
<long, 0>(), nullptr), "");
66 static_assert(testConstexprSpan(std::span
<double, 0>(), nullptr), "");
67 static_assert(testConstexprSpan(std::span
<A
, 0>(), nullptr), "");
68 static_assert(testConstexprSpan(std::span
<std::string
, 0>(), nullptr), "");
70 static_assert(testConstexprSpan(std::span
<const int, 1>(iArr1
, 1), iArr1
), "");
71 static_assert(testConstexprSpan(std::span
<const int, 2>(iArr1
, 2), iArr1
), "");
72 static_assert(testConstexprSpan(std::span
<const int, 3>(iArr1
, 3), iArr1
), "");
73 static_assert(testConstexprSpan(std::span
<const int, 4>(iArr1
, 4), iArr1
), "");
75 static_assert(testConstexprSpan(std::span
<const int, 1>(iArr1
+ 1, 1), iArr1
+ 1), "");
76 static_assert(testConstexprSpan(std::span
<const int, 2>(iArr1
+ 2, 2), iArr1
+ 2), "");
77 static_assert(testConstexprSpan(std::span
<const int, 3>(iArr1
+ 3, 3), iArr1
+ 3), "");
78 static_assert(testConstexprSpan(std::span
<const int, 4>(iArr1
+ 4, 4), iArr1
+ 4), "");
82 testRuntimeSpan(std::span
<int>(), nullptr);
83 testRuntimeSpan(std::span
<long>(), nullptr);
84 testRuntimeSpan(std::span
<double>(), nullptr);
85 testRuntimeSpan(std::span
<A
>(), nullptr);
86 testRuntimeSpan(std::span
<std::string
>(), nullptr);
88 testRuntimeSpan(std::span
<int>(iArr2
, 1), iArr2
);
89 testRuntimeSpan(std::span
<int>(iArr2
, 2), iArr2
);
90 testRuntimeSpan(std::span
<int>(iArr2
, 3), iArr2
);
91 testRuntimeSpan(std::span
<int>(iArr2
, 4), iArr2
);
93 testRuntimeSpan(std::span
<int>(iArr2
+ 1, 1), iArr2
+ 1);
94 testRuntimeSpan(std::span
<int>(iArr2
+ 2, 2), iArr2
+ 2);
95 testRuntimeSpan(std::span
<int>(iArr2
+ 3, 3), iArr2
+ 3);
96 testRuntimeSpan(std::span
<int>(iArr2
+ 4, 4), iArr2
+ 4);
99 testRuntimeSpan(std::span
<int, 0>(), nullptr);
100 testRuntimeSpan(std::span
<long, 0>(), nullptr);
101 testRuntimeSpan(std::span
<double, 0>(), nullptr);
102 testRuntimeSpan(std::span
<A
, 0>(), nullptr);
103 testRuntimeSpan(std::span
<std::string
, 0>(), nullptr);
105 testRuntimeSpan(std::span
<int, 1>(iArr2
, 1), iArr2
);
106 testRuntimeSpan(std::span
<int, 2>(iArr2
, 2), iArr2
);
107 testRuntimeSpan(std::span
<int, 3>(iArr2
, 3), iArr2
);
108 testRuntimeSpan(std::span
<int, 4>(iArr2
, 4), iArr2
);
110 testRuntimeSpan(std::span
<int, 1>(iArr2
+ 1, 1), iArr2
+ 1);
111 testRuntimeSpan(std::span
<int, 2>(iArr2
+ 2, 2), iArr2
+ 2);
112 testRuntimeSpan(std::span
<int, 3>(iArr2
+ 3, 3), iArr2
+ 3);
113 testRuntimeSpan(std::span
<int, 4>(iArr2
+ 4, 4), iArr2
+ 4);
117 testRuntimeSpan(std::span
<std::string
>(&s
, 1), &s
);
118 testRuntimeSpan(std::span
<std::string
, 1>(&s
, 1), &s
);