From c143a07f61f5e1cb2be8e3f7676ae869efd18e7c Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 28 May 2020 18:00:40 -0700 Subject: [PATCH] Add string_view test case and modify deduction guides --- include/gsl/span | 10 ++++++---- tests/span_tests.cpp | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/include/gsl/span b/include/gsl/span index c7b45e9..3022e0d 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -740,11 +740,13 @@ span(std::array&)->span; template span(const std::array&)->span; -template -span(Container&)->span; +template ().data())>> +span(Container&)->span; -template -span(const Container&)->span; +template ().data())>> +span(const Container&)->span; #endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) ) diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index f53518b..d27d645 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -31,6 +31,13 @@ #include // for vector #include +#ifdef __has_include +#if __has_include() +#include +#define HAS_STRING_VIEW +#endif +#endif + using namespace std; using namespace gsl; @@ -1234,11 +1241,20 @@ TEST(span_test, from_array_constructor) { 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 }