Merge pull request #6 from CaseyCarter/deduction_guides

Add string_view test case and modify deduction guides
This commit is contained in:
Jordan Maples [MSFT] 2020-05-29 10:16:06 -07:00 committed by GitHub
commit 9720cc552a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -740,11 +740,13 @@ span(std::array<Type, Size>&)->span<Type, Size>;
template <class Type, std::size_t Size> template <class Type, std::size_t Size>
span(const std::array<Type, Size>&)->span<const Type, Size>; span(const std::array<Type, Size>&)->span<const Type, Size>;
template <class Container> template <class Container,
span(Container&)->span<typename Container::value_type>; class Element = std::remove_pointer_t<decltype(std::declval<Container&>().data())>>
span(Container&)->span<Element>;
template <class Container> template <class Container,
span(const Container&)->span<const typename Container::value_type>; 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) ) #endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) )

View File

@ -31,6 +31,13 @@
#include <vector> // for vector #include <vector> // for vector
#include <utility> #include <utility>
#ifdef __has_include
#if __has_include(<string_view>)
#include <string_view>
#define HAS_STRING_VIEW
#endif
#endif
using namespace std; using namespace std;
using namespace gsl; using namespace gsl;
@ -1234,11 +1241,20 @@ TEST(span_test, from_array_constructor)
{ {
std::vector v{1,2,3,4}; std::vector v{1,2,3,4};
gsl::span sp{v}; gsl::span sp{v};
static_assert(std::is_same<decltype(sp), gsl::span<int>>::value);
} }
{ {
std::string str{"foo"}; std::string str{"foo"};
gsl::span sp{str}; 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 #endif
} }