Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/microsoft/GSL.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Maples [MSFT] <49793787+JordanMaples@users.noreply.github.com>2020-05-29 20:16:06 +0300
committerGitHub <noreply@github.com>2020-05-29 20:16:06 +0300
commit9720cc552ac6565bcba343bfaaa5d9bf2dccaa29 (patch)
tree319645bcefc75a4fd30fa2fbf1f0414dd99fa453
parent6c405a1b7f49da97124b79b2d667c9c75b271701 (diff)
parentc143a07f61f5e1cb2be8e3f7676ae869efd18e7c (diff)
Merge pull request #6 from CaseyCarter/deduction_guides
Add string_view test case and modify deduction guides
-rw-r--r--include/gsl/span10
-rw-r--r--tests/span_tests.cpp16
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<Type, Size>&)->span<Type, Size>;
template <class Type, std::size_t Size>
span(const std::array<Type, Size>&)->span<const Type, Size>;
-template <class Container>
-span(Container&)->span<typename Container::value_type>;
+template <class Container,
+ class Element = std::remove_pointer_t<decltype(std::declval<Container&>().data())>>
+span(Container&)->span<Element>;
-template <class Container>
-span(const Container&)->span<const typename Container::value_type>;
+template <class Container,
+ class Element = std::remove_pointer_t<decltype(std::declval<const Container&>().data())>>
+span(const Container&)->span<Element>;
#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 <vector> // for vector
#include <utility>
+#ifdef __has_include
+#if __has_include(<string_view>)
+#include <string_view>
+#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<decltype(sp), gsl::span<int>>::value);
}
{
std::string str{"foo"};
gsl::span sp{str};
+ static_assert(std::is_same<decltype(sp), gsl::span<char>>::value);
}
+#ifdef HAS_STRING_VIEW
+ {
+ std::string_view sv{"foo"};
+ gsl::span sp{sv};
+ static_assert(std::is_same<decltype(sp), gsl::span<const char>>::value);
+ }
+#endif
#endif
}