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
21void checkCV() {
22 // Types the same (dynamic sized)
23 {
24 std::span< int> s1;
25 std::span<const int> s2;
26 std::span< volatile int> s3;
27 std::span<const volatile int> s4;
28 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
29 }
30
31 // Types the same (static sized)
32 {
33 std::span< int, 0> s1;
34 std::span<const int, 0> s2;
35 std::span< volatile int, 0> s3;
36 std::span<const volatile int, 0> s4;
37 assert(s1.size() + s2.size() + s3.size() + s4.size() == 0);
38 }
39}
40
41template <typename T>
42constexpr bool testConstexprSpan() {
43 std::span<const T> s1;
44 std::span<const T, 0> s2;
45 return s1.data() == nullptr && s1.size() == 0 && s2.data() == nullptr && s2.size() == 0;
46}
47
48template <typename T>
49void testRuntimeSpan() {
50 ASSERT_NOEXCEPT(T{});
51 std::span<const T> s1;
52 std::span<const T, 0> s2;
53 assert(s1.data() == nullptr && s1.size() == 0);
54 assert(s2.data() == nullptr && s2.size() == 0);
55}
56
57struct A {};
58
59int main(int, char**) {
60 static_assert(testConstexprSpan<int>(), "");
61 static_assert(testConstexprSpan<long>(), "");
62 static_assert(testConstexprSpan<double>(), "");
63 static_assert(testConstexprSpan<A>(), "");
64
65 testRuntimeSpan<int>();
66 testRuntimeSpan<long>();
67 testRuntimeSpan<double>();
68 testRuntimeSpan<std::string>();
69 testRuntimeSpan<A>();
70
71 checkCV();
72
73 static_assert(std::is_default_constructible_v<std::span<int, std::dynamic_extent>>, "");
74 static_assert(std::is_default_constructible_v<std::span<int, 0>>, "");
75 static_assert(!std::is_default_constructible_v<std::span<int, 2>>, "");
76
77 return 0;
78}
79

source code of libcxx/test/std/containers/views/views.span/span.cons/default.pass.cpp