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(const span& other) noexcept = default; 15 16 #include <span> 17 #include <cassert> 18 #include <string> 19 20 #include "test_macros.h" 21 22 template <typename T> 23 constexpr bool doCopy(const T &rhs) 24 { 25 ASSERT_NOEXCEPT(T{rhs}); 26 T lhs{rhs}; 27 return lhs.data() == rhs.data() 28 && lhs.size() == rhs.size(); 29 } 30 31 struct A{}; 32 33 template <typename T> 34 void testCV () 35 { 36 int arr[] = {1,2,3}; 37 assert((doCopy(std::span<T> () ))); 38 assert((doCopy(std::span<T,0>() ))); 39 assert((doCopy(std::span<T> (&arr[0], 1)))); 40 assert((doCopy(std::span<T,1>(&arr[0], 1)))); 41 assert((doCopy(std::span<T> (&arr[0], 2)))); 42 assert((doCopy(std::span<T,2>(&arr[0], 2)))); 43 } 44 45 46 int main () 47 { 48 constexpr int carr[] = {1,2,3}; 49 50 static_assert(doCopy(std::span< int> ()), ""); 51 static_assert(doCopy(std::span< int,0>()), ""); 52 static_assert(doCopy(std::span<const int> (&carr[0], 1)), ""); 53 static_assert(doCopy(std::span<const int,1>(&carr[0], 1)), ""); 54 static_assert(doCopy(std::span<const int> (&carr[0], 2)), ""); 55 static_assert(doCopy(std::span<const int,2>(&carr[0], 2)), ""); 56 57 static_assert(doCopy(std::span<long>()), ""); 58 static_assert(doCopy(std::span<double>()), ""); 59 static_assert(doCopy(std::span<A>()), ""); 60 61 std::string s; 62 assert(doCopy(std::span<std::string> () )); 63 assert(doCopy(std::span<std::string, 0>() )); 64 assert(doCopy(std::span<std::string> (&s, 1))); 65 assert(doCopy(std::span<std::string, 1>(&s, 1))); 66 67 testCV< int>(); 68 testCV<const int>(); 69 testCV< volatile int>(); 70 testCV<const volatile int>(); 71 } 72