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 span() noexcept;
18 #include <type_traits>
20 #include "test_macros.h"
24 // Types the same (dynamic sized)
27 std::span
<const int> s2
;
28 std::span
< volatile int> s3
;
29 std::span
<const volatile int> s4
;
30 assert(s1
.size() + s2
.size() + s3
.size() + s4
.size() == 0);
33 // Types the same (static sized)
36 std::span
<const int,0> s2
;
37 std::span
< volatile int,0> s3
;
38 std::span
<const volatile int,0> s4
;
39 assert(s1
.size() + s2
.size() + s3
.size() + s4
.size() == 0);
45 constexpr bool testConstexprSpan()
47 std::span
<const T
> s1
;
48 std::span
<const T
, 0> s2
;
50 s1
.data() == nullptr && s1
.size() == 0
51 && s2
.data() == nullptr && s2
.size() == 0;
56 void testRuntimeSpan()
59 std::span
<const T
> s1
;
60 std::span
<const T
, 0> s2
;
61 assert(s1
.data() == nullptr && s1
.size() == 0);
62 assert(s2
.data() == nullptr && s2
.size() == 0);
70 static_assert(testConstexprSpan
<int>(), "");
71 static_assert(testConstexprSpan
<long>(), "");
72 static_assert(testConstexprSpan
<double>(), "");
73 static_assert(testConstexprSpan
<A
>(), "");
75 testRuntimeSpan
<int>();
76 testRuntimeSpan
<long>();
77 testRuntimeSpan
<double>();
78 testRuntimeSpan
<std::string
>();
83 static_assert( std::is_default_constructible_v
<std::span
<int, std::dynamic_extent
>>, "");
84 static_assert( std::is_default_constructible_v
<std::span
<int, 0>>, "");
85 static_assert(!std::is_default_constructible_v
<std::span
<int, 2>>, "");