diff --git a/include/gsl/span b/include/gsl/span index 04d2d69..3022e0d 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -740,6 +740,14 @@ span(std::array&)->span; template span(const std::array&)->span; +template ().data())>> +span(Container&)->span; + +template ().data())>> +span(const Container&)->span; + #endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) ) #if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND) diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index ce881ba..6caaeea 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -31,6 +31,16 @@ #include // for vector #include +// the string_view include and macro are used in the deduction guide verification +#if (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L)) +#ifdef __has_include +#if __has_include() +#include +#define HAS_STRING_VIEW +#endif // __has_include() +#endif // __has_include +#endif // (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L)) + using namespace std; using namespace gsl; @@ -1227,6 +1237,30 @@ TEST(span_test, from_array_constructor) EXPECT_FALSE((std::is_default_constructible>::value)); } + TEST(span_test, std_container_ctad) + { +#if (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L)) + // this test is just to verify that these compile + { + std::vector v{1,2,3,4}; + gsl::span sp{v}; + static_assert(std::is_same>::value); + } + { + std::string str{"foo"}; + gsl::span sp{str}; + static_assert(std::is_same>::value); + } +#ifdef HAS_STRING_VIEW + { + std::string_view sv{"foo"}; + gsl::span sp{sv}; + static_assert(std::is_same>::value); + } +#endif +#endif + } + TEST(span_test, front_back) { int arr[5] = {1,2,3,4,5};