1 // -*- C++ -*- 2 //===------------------------------ span ---------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===---------------------------------------------------------------------===// 10 // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 11 12 // <span> 13 14 // constexpr span() noexcept; 15 16 #include <span> 17 #include <cassert> 18 #include <string> 19 20 #include "test_macros.h" 21 22 void checkCV() 23 { 24 // Types the same (dynamic sized) 25 { 26 std::span< int> s1; 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); 31 } 32 33 // Types the same (static sized) 34 { 35 std::span< int,0> s1; 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); 40 } 41 } 42 43 44 template <typename T> 45 constexpr bool testConstexprSpan() 46 { 47 std::span<const T> s1; 48 std::span<const T, 0> s2; 49 return 50 s1.data() == nullptr && s1.size() == 0 51 && s2.data() == nullptr && s2.size() == 0; 52 } 53 54 55 template <typename T> 56 void testRuntimeSpan() 57 { 58 ASSERT_NOEXCEPT(T{}); 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); 63 } 64 65 66 struct A{}; 67 68 int main () 69 { 70 static_assert(testConstexprSpan<int>(), ""); 71 static_assert(testConstexprSpan<long>(), ""); 72 static_assert(testConstexprSpan<double>(), ""); 73 static_assert(testConstexprSpan<A>(), ""); 74 75 testRuntimeSpan<int>(); 76 testRuntimeSpan<long>(); 77 testRuntimeSpan<double>(); 78 testRuntimeSpan<std::string>(); 79 testRuntimeSpan<A>(); 80 81 checkCV(); 82 } 83