1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 // UNSUPPORTED: c++03, c++11, c++14, c++17
9
10 // <span>
11
12 // constexpr span() noexcept;
13
14 #include <span>
15 #include <cassert>
16 #include <string>
17 #include <type_traits>
18
19 #include "test_macros.h"
20
checkCV()21 void checkCV()
22 {
23 // Types the same (dynamic sized)
24 {
25 std::span< int> s1;
26 std::span<const int> s2;
27 std::span< volatile int> s3;
28 std::span<const volatile int> s4;
29 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
30 }
31
32 // Types the same (static sized)
33 {
34 std::span< int,0> s1;
35 std::span<const int,0> s2;
36 std::span< volatile int,0> s3;
37 std::span<const volatile int,0> s4;
38 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
39 }
40 }
41
42
43 template <typename T>
testConstexprSpan()44 constexpr bool testConstexprSpan()
45 {
46 std::span<const T> s1;
47 std::span<const T, 0> s2;
48 return
49 s1.data() == nullptr && s1.size() == 0
50 && s2.data() == nullptr && s2.size() == 0;
51 }
52
53
54 template <typename T>
testRuntimeSpan()55 void testRuntimeSpan()
56 {
57 ASSERT_NOEXCEPT(T{});
58 std::span<const T> s1;
59 std::span<const T, 0> s2;
60 assert(s1.data() == nullptr && s1.size() == 0);
61 assert(s2.data() == nullptr && s2.size() == 0);
62 }
63
64
65 struct A{};
66
main(int,char **)67 int main(int, char**)
68 {
69 static_assert(testConstexprSpan<int>(), "");
70 static_assert(testConstexprSpan<long>(), "");
71 static_assert(testConstexprSpan<double>(), "");
72 static_assert(testConstexprSpan<A>(), "");
73
74 testRuntimeSpan<int>();
75 testRuntimeSpan<long>();
76 testRuntimeSpan<double>();
77 testRuntimeSpan<std::string>();
78 testRuntimeSpan<A>();
79
80 checkCV();
81
82 static_assert( std::is_default_constructible_v<std::span<int, std::dynamic_extent>>, "");
83 static_assert( std::is_default_constructible_v<std::span<int, 0>>, "");
84 static_assert(!std::is_default_constructible_v<std::span<int, 2>>, "");
85
86 return 0;
87 }
88