Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9720cc5

Browse files
authored
Merge pull request #6 from CaseyCarter/deduction_guides
Add string_view test case and modify deduction guides
2 parents 6c405a1 + c143a07 commit 9720cc5

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

include/gsl/span

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -740,11 +740,13 @@ span(std::array<Type, Size>&)->span<Type, Size>;
740740
template <class Type, std::size_t Size>
741741
span(const std::array<Type, Size>&)->span<const Type, Size>;
742742

743-
template <class Container>
744-
span(Container&)->span<typename Container::value_type>;
743+
template <class Container,
744+
class Element = std::remove_pointer_t<decltype(std::declval<Container&>().data())>>
745+
span(Container&)->span<Element>;
745746

746-
template <class Container>
747-
span(const Container&)->span<const typename Container::value_type>;
747+
template <class Container,
748+
class Element = std::remove_pointer_t<decltype(std::declval<const Container&>().data())>>
749+
span(const Container&)->span<Element>;
748750

749751
#endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) )
750752

tests/span_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
#include <vector> // for vector
3232
#include <utility>
3333

34+
#ifdef __has_include
35+
#if __has_include(<string_view>)
36+
#include <string_view>
37+
#define HAS_STRING_VIEW
38+
#endif
39+
#endif
40+
3441
using namespace std;
3542
using namespace gsl;
3643

@@ -1234,11 +1241,20 @@ TEST(span_test, from_array_constructor)
12341241
{
12351242
std::vector v{1,2,3,4};
12361243
gsl::span sp{v};
1244+
static_assert(std::is_same<decltype(sp), gsl::span<int>>::value);
12371245
}
12381246
{
12391247
std::string str{"foo"};
12401248
gsl::span sp{str};
1249+
static_assert(std::is_same<decltype(sp), gsl::span<char>>::value);
12411250
}
1251+
#ifdef HAS_STRING_VIEW
1252+
{
1253+
std::string_view sv{"foo"};
1254+
gsl::span sp{sv};
1255+
static_assert(std::is_same<decltype(sp), gsl::span<const char>>::value);
1256+
}
1257+
#endif
12421258
#endif
12431259
}
12441260

0 commit comments

Comments
 (0)