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 bool empty() const noexcept; 15 // 16 17 18 #include <span> 19 #include <cassert> 20 #include <string> 21 22 #include "test_macros.h" 23 24 struct A{}; 25 constexpr int iArr1[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; 26 int iArr2[] = {10, 11, 12, 13, 14, 15, 16, 17, 18, 19}; 27 28 int main () 29 { 30 static_assert( noexcept(std::span<int> ().empty()), ""); 31 static_assert( noexcept(std::span<int, 0>().empty()), ""); 32 33 34 static_assert( std::span<int>().empty(), ""); 35 static_assert( std::span<long>().empty(), ""); 36 static_assert( std::span<double>().empty(), ""); 37 static_assert( std::span<A>().empty(), ""); 38 static_assert( std::span<std::string>().empty(), ""); 39 40 static_assert( std::span<int, 0>().empty(), ""); 41 static_assert( std::span<long, 0>().empty(), ""); 42 static_assert( std::span<double, 0>().empty(), ""); 43 static_assert( std::span<A, 0>().empty(), ""); 44 static_assert( std::span<std::string, 0>().empty(), ""); 45 46 static_assert(!std::span<const int>(iArr1, 1).empty(), ""); 47 static_assert(!std::span<const int>(iArr1, 2).empty(), ""); 48 static_assert(!std::span<const int>(iArr1, 3).empty(), ""); 49 static_assert(!std::span<const int>(iArr1, 4).empty(), ""); 50 static_assert(!std::span<const int>(iArr1, 5).empty(), ""); 51 52 assert( (std::span<int>().empty() )); 53 assert( (std::span<long>().empty() )); 54 assert( (std::span<double>().empty() )); 55 assert( (std::span<A>().empty() )); 56 assert( (std::span<std::string>().empty() )); 57 58 assert( (std::span<int, 0>().empty() )); 59 assert( (std::span<long, 0>().empty() )); 60 assert( (std::span<double, 0>().empty() )); 61 assert( (std::span<A, 0>().empty() )); 62 assert( (std::span<std::string, 0>().empty())); 63 64 assert(!(std::span<int, 1>(iArr2, 1).empty())); 65 assert(!(std::span<int, 2>(iArr2, 2).empty())); 66 assert(!(std::span<int, 3>(iArr2, 3).empty())); 67 assert(!(std::span<int, 4>(iArr2, 4).empty())); 68 assert(!(std::span<int, 5>(iArr2, 5).empty())); 69 70 std::string s; 71 assert( ((std::span<std::string>(&s, (std::ptrdiff_t) 0)).empty())); 72 assert(!((std::span<std::string>(&s, 1).empty()))); 73 } 74