mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Merge branch 'master' into dev/neilmac/contracts
This commit is contained in:
commit
d5057370b8
@ -1275,7 +1275,7 @@ public:
|
||||
&& std::is_convertible<DataType (*)[], value_type (*)[]>::value
|
||||
&& std::is_same<std::decay_t<decltype(std::declval<Cont>().size(), *std::declval<Cont>().data())>, DataType>::value>
|
||||
>
|
||||
constexpr span (Cont& cont) : span(static_cast<pointer>(cont.data()), details::newBoundsHelper<bounds_type>(cont.size()))
|
||||
constexpr span (Cont& cont) : span(static_cast<pointer>(cont.data()), details::newBoundsHelper<bounds_type>(static_cast<size_type>(cont.size())))
|
||||
{}
|
||||
|
||||
constexpr span(const span &) = default;
|
||||
@ -1443,7 +1443,7 @@ public:
|
||||
return m_pdata;
|
||||
}
|
||||
|
||||
constexpr operator bool() const noexcept
|
||||
constexpr explicit operator bool() const noexcept
|
||||
{
|
||||
return m_pdata != nullptr;
|
||||
}
|
||||
@ -1577,6 +1577,14 @@ template <typename Cont>
|
||||
constexpr auto as_span(Cont &&arr) -> std::enable_if_t<!details::is_span<std::decay_t<Cont>>::value,
|
||||
span<std::remove_reference_t<decltype(arr.size(), *arr.data())>, dynamic_range>> = delete;
|
||||
|
||||
// from basic_string which doesn't have nonconst .data() member like other contiguous containers
|
||||
template <typename CharT, typename Traits, typename Allocator>
|
||||
constexpr auto as_span(std::basic_string<CharT, Traits, Allocator> &str) -> span<CharT, dynamic_range>
|
||||
{
|
||||
Expects(str.size() < PTRDIFF_MAX);
|
||||
return {&str[0], static_cast<std::ptrdiff_t>(str.size())};
|
||||
}
|
||||
|
||||
template <typename ValueType, size_t Rank>
|
||||
class strided_span
|
||||
{
|
||||
@ -1621,8 +1629,12 @@ public:
|
||||
{}
|
||||
|
||||
// from array view
|
||||
template <std::ptrdiff_t... Dimensions, typename Dummy = std::enable_if<sizeof...(Dimensions) == Rank>>
|
||||
constexpr strided_span(span<ValueType, Dimensions...> av, bounds_type bounds) : strided_span(av.data(), av.bounds().total_size(), std::move(bounds))
|
||||
template <typename OtherValueType, std::ptrdiff_t... Dimensions,
|
||||
bool Enabled1 = (sizeof...(Dimensions) == Rank),
|
||||
bool Enabled2 = std::is_convertible<OtherValueType*, ValueType*>::value,
|
||||
typename Dummy = std::enable_if_t<Enabled1 && Enabled2>
|
||||
>
|
||||
constexpr strided_span(span<OtherValueType, Dimensions...> av, bounds_type bounds) : strided_span(av.data(), av.bounds().total_size(), std::move(bounds))
|
||||
{}
|
||||
|
||||
// convertible
|
||||
@ -1688,7 +1700,7 @@ public:
|
||||
return m_pdata;
|
||||
}
|
||||
|
||||
constexpr operator bool() const noexcept
|
||||
constexpr explicit operator bool() const noexcept
|
||||
{
|
||||
return m_pdata != nullptr;
|
||||
}
|
||||
|
@ -203,6 +203,15 @@ SUITE(span_tests)
|
||||
overloaded_func(av3.as_span(dim<>(1), dim<3>(), dim<5>()), 't');
|
||||
}
|
||||
|
||||
{
|
||||
string str;
|
||||
span<char> strspan = as_span(str);
|
||||
(void)strspan;
|
||||
const string cstr;
|
||||
span<const char> cstrspan = as_span(cstr);
|
||||
(void)cstrspan;
|
||||
}
|
||||
|
||||
{
|
||||
int a[3][4][5];
|
||||
auto av = as_span(a);
|
||||
@ -333,7 +342,7 @@ SUITE(span_tests)
|
||||
CHECK(sav_c[1] == 2);
|
||||
|
||||
#if _MSC_VER > 1800
|
||||
strided_span<volatile int, 1> sav_v{ {src}, {2, 1} };
|
||||
strided_span<volatile int, 1> sav_v{ src, {2, 1} };
|
||||
#else
|
||||
strided_span<volatile int, 1> sav_v{ span<volatile int>{src}, strided_bounds<1>{2, 1} };
|
||||
#endif
|
||||
@ -342,7 +351,7 @@ SUITE(span_tests)
|
||||
CHECK(sav_v[1] == 2);
|
||||
|
||||
#if _MSC_VER > 1800
|
||||
strided_span<const volatile int, 1> sav_cv{ {src}, {2, 1} };
|
||||
strided_span<const volatile int, 1> sav_cv{ src, {2, 1} };
|
||||
#else
|
||||
strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} };
|
||||
#endif
|
||||
@ -361,7 +370,7 @@ SUITE(span_tests)
|
||||
CHECK(sav_c[1] == 2);
|
||||
|
||||
#if _MSC_VER > 1800
|
||||
strided_span<const volatile int, 1> sav_cv{ {src}, {2, 1} };
|
||||
strided_span<const volatile int, 1> sav_cv{ src, {2, 1} };
|
||||
#else
|
||||
strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} };
|
||||
#endif
|
||||
@ -381,7 +390,7 @@ SUITE(span_tests)
|
||||
CHECK(sav_v[1] == 2);
|
||||
|
||||
#if _MSC_VER > 1800
|
||||
strided_span<const volatile int, 1> sav_cv{ {src}, {2, 1} };
|
||||
strided_span<const volatile int, 1> sav_cv{ src, {2, 1} };
|
||||
#else
|
||||
strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} };
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user