From 689abc29828b6ad0aaf4fd555e5d979e42186fca Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Thu, 28 May 2020 14:04:31 -0700 Subject: [PATCH 1/6] adding container ctad --- include/gsl/span | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/gsl/span b/include/gsl/span index 04d2d69..c7b45e9 100644 --- a/include/gsl/span +++ b/include/gsl/span @@ -740,6 +740,12 @@ span(std::array&)->span; template span(const std::array&)->span; +template +span(Container&)->span; + +template +span(const Container&)->span; + #endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) ) #if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND) From 6c405a1b7f49da97124b79b2d667c9c75b271701 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Thu, 28 May 2020 17:18:08 -0700 Subject: [PATCH 2/6] adding a test to verify that the additional ctad works --- tests/span_tests.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index ce881ba..f53518b 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -1227,6 +1227,21 @@ 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}; + } + { + std::string str{"foo"}; + gsl::span sp{str}; + } +#endif + } + TEST(span_test, front_back) { int arr[5] = {1,2,3,4,5}; From c143a07f61f5e1cb2be8e3f7676ae869efd18e7c Mon Sep 17 00:00:00 2001 From: Casey Carter Date: Thu, 28 May 2020 18:00:40 -0700 Subject: [PATCH 3/6] 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 } From c4a2ce6cc8aa2a638b088711a2547234c67b2ea3 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Fri, 29 May 2020 10:53:30 -0700 Subject: [PATCH 4/6] wrapping string_view checks in deduction guide checks to prevent 'macro unused' errors --- tests/span_tests.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index d27d645..ee23009 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -31,12 +31,15 @@ #include // for vector #include +// the string_view include and macro are used in the deduciton guide verification +#if (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L)) #ifdef __has_include #if __has_include() #include #define HAS_STRING_VIEW -#endif -#endif +#endif // __has_include() +#endif // __has_include +#endif // (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L)) using namespace std; using namespace gsl; From 4d2090ebc41dc19b312ebbddc28660421bcaaf23 Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Fri, 29 May 2020 10:54:13 -0700 Subject: [PATCH 5/6] fixed typo --- tests/span_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index ee23009..db536fa 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -31,7 +31,7 @@ #include // for vector #include -// the string_view include and macro are used in the deduciton guide verification +// 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() From 72803a7ecb2c0868753488246c5d46489414954b Mon Sep 17 00:00:00 2001 From: Jordan Maples Date: Fri, 29 May 2020 15:45:25 -0700 Subject: [PATCH 6/6] adding template type to the vector to suppress clang-10 warning that vector may not intend for type deduction. --- tests/span_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index db536fa..6caaeea 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -1242,7 +1242,7 @@ TEST(span_test, from_array_constructor) #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}; + std::vector v{1,2,3,4}; gsl::span sp{v}; static_assert(std::is_same>::value); }