// -*- C++ -*- //===------------------------------ span ---------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===---------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17 // // template // span(T (&)[N]) -> span; // // template // span(array&) -> span; // // template // span(const array&) -> span; // // template // span(Container&) -> span; // // template // span(const Container&) -> span; #include #include #include #include #include #include #include "test_macros.h" // std::array is explicitly allowed to be initialized with A a = { init-list };. // Disable the missing braces warning for this reason. #include "disable_missing_braces_warning.h" int main () { { int arr[] = {1,2,3}; std::span s{arr}; using S = decltype(s); ASSERT_SAME_TYPE(S, std::span); assert((std::equal(std::begin(arr), std::end(arr), s.begin(), s.end()))); } { std::array arr = {1.0, 2.0, 3.0, 4.0}; std::span s{arr}; using S = decltype(s); ASSERT_SAME_TYPE(S, std::span); assert((std::equal(std::begin(arr), std::end(arr), s.begin(), s.end()))); } { const std::array arr = {4, 5, 6, 7, 8}; std::span s{arr}; using S = decltype(s); ASSERT_SAME_TYPE(S, std::span); assert((std::equal(std::begin(arr), std::end(arr), s.begin(), s.end()))); } { std::string str{"ABCDE"}; std::span s{str}; using S = decltype(s); ASSERT_SAME_TYPE(S, std::span); assert((size_t)s.size() == str.size()); assert((std::equal(s.begin(), s.end(), std::begin(s), std::end(s)))); } { const std::string str{"QWERTYUIOP"}; std::span s{str}; using S = decltype(s); ASSERT_SAME_TYPE(S, std::span); assert((size_t)s.size() == str.size()); assert((std::equal(s.begin(), s.end(), std::begin(s), std::end(s)))); } }