mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge pull request #891 from JordanMaples/dev/jomaples/missing_span_ctad
Adding missing span deduction guides
This commit is contained in:
commit
794d7bb69b
@ -740,6 +740,14 @@ 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,
|
||||||
|
class Element = std::remove_pointer_t<decltype(std::declval<Container&>().data())>>
|
||||||
|
span(Container&)->span<Element>;
|
||||||
|
|
||||||
|
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) )
|
#endif // ( defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L) )
|
||||||
|
|
||||||
#if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND)
|
#if defined(GSL_USE_STATIC_CONSTEXPR_WORKAROUND)
|
||||||
|
@ -31,6 +31,16 @@
|
|||||||
#include <vector> // for vector
|
#include <vector> // for vector
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
// 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(<string_view>)
|
||||||
|
#include <string_view>
|
||||||
|
#define HAS_STRING_VIEW
|
||||||
|
#endif // __has_include(<string_view>)
|
||||||
|
#endif // __has_include
|
||||||
|
#endif // (defined(__cpp_deduction_guides) && (__cpp_deduction_guides >= 201611L))
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace gsl;
|
using namespace gsl;
|
||||||
|
|
||||||
@ -1227,6 +1237,30 @@ TEST(span_test, from_array_constructor)
|
|||||||
EXPECT_FALSE((std::is_default_constructible<span<int, 42>>::value));
|
EXPECT_FALSE((std::is_default_constructible<span<int, 42>>::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<int> 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
|
||||||
|
}
|
||||||
|
|
||||||
TEST(span_test, front_back)
|
TEST(span_test, front_back)
|
||||||
{
|
{
|
||||||
int arr[5] = {1,2,3,4,5};
|
int arr[5] = {1,2,3,4,5};
|
||||||
|
Loading…
Reference in New Issue
Block a user