// -*- 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 // constexpr span(Container& cont); // template // constexpr span(const Container& cont); // // Remarks: These constructors shall not participate in overload resolution unless: // — Container is not a specialization of span, // — Container is not a specialization of array, // — is_array_v is false, // — data(cont) and size(cont) are both well-formed, and // — remove_pointer_t(*)[] is convertible to ElementType(*)[]. // #include #include #include #include #include #include "test_macros.h" // Look ma - I'm a container! template struct IsAContainer { constexpr IsAContainer() : v_{} {} constexpr size_t size() const {return 1;} constexpr T *data() {return &v_;} constexpr const T *data() const {return &v_;} constexpr const T *getV() const {return &v_;} // for checking T v_; }; template struct NotAContainerNoData { size_t size() const {return 0;} }; template struct NotAContainerNoSize { const T *data() const {return nullptr;} }; template struct NotAContainerPrivate { private: size_t size() const {return 0;} const T *data() const {return nullptr;} }; int main () { // Missing size and/or data { std::span s1{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s2{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s3{NotAContainerNoData()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s4{NotAContainerNoData()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s5{NotAContainerNoSize()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s6{NotAContainerNoSize()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s7{NotAContainerPrivate()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s8{NotAContainerPrivate()}; // expected-error {{no matching constructor for initialization of 'std::span'}} // Again with the standard containers std::span s11{std::deque()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s12{std::deque()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s13{std::list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s14{std::list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s15{std::forward_list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s16{std::forward_list()}; // expected-error {{no matching constructor for initialization of 'std::span'}} } // Not the same type { std::span s1{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s2{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} } // CV wrong (dynamically sized) { std::span< int> s1{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< int> s2{IsAContainer< volatile int>()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< int> s3{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s4{IsAContainer< volatile int>()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s5{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< volatile int> s6{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< volatile int> s7{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} } // CV wrong (statically sized) { std::span< int,1> s1{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< int,1> s2{IsAContainer< volatile int>()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< int,1> s3{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s4{IsAContainer< volatile int>()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span s5{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< volatile int,1> s6{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} std::span< volatile int,1> s7{IsAContainer()}; // expected-error {{no matching constructor for initialization of 'std::span'}} } }