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 // template<class OtherElementType, size_t OtherExtent>
14 // constexpr span(const span<OtherElementType, OtherExtent>& s) noexcept;
16 // Remarks: This constructor shall not participate in overload resolution unless:
17 // Extent == dynamic_extent || Extent == OtherExtent is true, and
18 // OtherElementType(*)[] is convertible to ElementType(*)[].
25 #include "test_macros.h"
30 // std::span<const int> csp;
31 std::span
< volatile int> vsp
;
32 // std::span<const volatile int> cvsp;
34 std::span
< int, 0> sp0
;
35 // std::span<const int, 0> csp0;
36 std::span
< volatile int, 0> vsp0
;
37 // std::span<const volatile int, 0> cvsp0;
41 std::span
<const int> s1
{ sp
}; // a span<const int> pointing at int.
42 std::span
< volatile int> s2
{ sp
}; // a span< volatile int> pointing at int.
43 std::span
<const volatile int> s3
{ sp
}; // a span<const volatile int> pointing at int.
44 std::span
<const volatile int> s4
{ vsp
}; // a span<const volatile int> pointing at volatile int.
45 assert(s1
.size() + s2
.size() + s3
.size() + s4
.size() == 0);
50 std::span
<const int, 0> s1
{ sp0
}; // a span<const int> pointing at int.
51 std::span
< volatile int, 0> s2
{ sp0
}; // a span< volatile int> pointing at int.
52 std::span
<const volatile int, 0> s3
{ sp0
}; // a span<const volatile int> pointing at int.
53 std::span
<const volatile int, 0> s4
{ vsp0
}; // a span<const volatile int> pointing at volatile int.
54 assert(s1
.size() + s2
.size() + s3
.size() + s4
.size() == 0);
59 std::span
<const int> s1
{ sp0
}; // a span<const int> pointing at int.
60 std::span
< volatile int> s2
{ sp0
}; // a span< volatile int> pointing at int.
61 std::span
<const volatile int> s3
{ sp0
}; // a span<const volatile int> pointing at int.
62 std::span
<const volatile int> s4
{ vsp0
}; // a span<const volatile int> pointing at volatile int.
63 assert(s1
.size() + s2
.size() + s3
.size() + s4
.size() == 0);
66 // dynamic -> static (not allowed)
71 constexpr bool testConstexprSpan()
75 std::span
<T
> s2(s1
); // static -> dynamic
76 ASSERT_NOEXCEPT(std::span
<T
> {s0
});
77 ASSERT_NOEXCEPT(std::span
<T
, 0>{s1
});
78 ASSERT_NOEXCEPT(std::span
<T
> {s1
});
81 s1
.data() == nullptr && s1
.size() == 0
82 && s2
.data() == nullptr && s2
.size() == 0;
87 void testRuntimeSpan()
91 std::span
<T
> s2(s1
); // static -> dynamic
92 ASSERT_NOEXCEPT(std::span
<T
> {s0
});
93 ASSERT_NOEXCEPT(std::span
<T
, 0>{s1
});
94 ASSERT_NOEXCEPT(std::span
<T
> {s1
});
96 assert(s1
.data() == nullptr && s1
.size() == 0);
97 assert(s2
.data() == nullptr && s2
.size() == 0);
103 int main(int, char**)
105 static_assert(testConstexprSpan
<int>(), "");
106 static_assert(testConstexprSpan
<long>(), "");
107 static_assert(testConstexprSpan
<double>(), "");
108 static_assert(testConstexprSpan
<A
>(), "");
110 testRuntimeSpan
<int>();
111 testRuntimeSpan
<long>();
112 testRuntimeSpan
<double>();
113 testRuntimeSpan
<std::string
>();
114 testRuntimeSpan
<A
>();