Merge branch 'master' into dev/neilmac/contracts

This commit is contained in:
Neil MacIntosh 2015-11-20 17:14:21 -08:00
commit d5057370b8
2 changed files with 30 additions and 9 deletions

View File

@ -1275,7 +1275,7 @@ public:
&& std::is_convertible<DataType (*)[], value_type (*)[]>::value && std::is_convertible<DataType (*)[], value_type (*)[]>::value
&& std::is_same<std::decay_t<decltype(std::declval<Cont>().size(), *std::declval<Cont>().data())>, DataType>::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; constexpr span(const span &) = default;
@ -1443,7 +1443,7 @@ public:
return m_pdata; return m_pdata;
} }
constexpr operator bool() const noexcept constexpr explicit operator bool() const noexcept
{ {
return m_pdata != nullptr; 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, 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; 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> template <typename ValueType, size_t Rank>
class strided_span class strided_span
{ {
@ -1621,8 +1629,12 @@ public:
{} {}
// from array view // from array view
template <std::ptrdiff_t... Dimensions, typename Dummy = std::enable_if<sizeof...(Dimensions) == Rank>> template <typename OtherValueType, std::ptrdiff_t... Dimensions,
constexpr strided_span(span<ValueType, Dimensions...> av, bounds_type bounds) : strided_span(av.data(), av.bounds().total_size(), std::move(bounds)) 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 // convertible
@ -1688,7 +1700,7 @@ public:
return m_pdata; return m_pdata;
} }
constexpr operator bool() const noexcept constexpr explicit operator bool() const noexcept
{ {
return m_pdata != nullptr; return m_pdata != nullptr;
} }

View File

@ -203,6 +203,15 @@ SUITE(span_tests)
overloaded_func(av3.as_span(dim<>(1), dim<3>(), dim<5>()), 't'); 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]; int a[3][4][5];
auto av = as_span(a); auto av = as_span(a);
@ -333,7 +342,7 @@ SUITE(span_tests)
CHECK(sav_c[1] == 2); CHECK(sav_c[1] == 2);
#if _MSC_VER > 1800 #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 #else
strided_span<volatile int, 1> sav_v{ span<volatile int>{src}, strided_bounds<1>{2, 1} }; strided_span<volatile int, 1> sav_v{ span<volatile int>{src}, strided_bounds<1>{2, 1} };
#endif #endif
@ -342,7 +351,7 @@ SUITE(span_tests)
CHECK(sav_v[1] == 2); CHECK(sav_v[1] == 2);
#if _MSC_VER > 1800 #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 #else
strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} }; strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} };
#endif #endif
@ -361,7 +370,7 @@ SUITE(span_tests)
CHECK(sav_c[1] == 2); CHECK(sav_c[1] == 2);
#if _MSC_VER > 1800 #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 #else
strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} }; strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} };
#endif #endif
@ -381,7 +390,7 @@ SUITE(span_tests)
CHECK(sav_v[1] == 2); CHECK(sav_v[1] == 2);
#if _MSC_VER > 1800 #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 #else
strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} }; strided_span<const volatile int, 1> sav_cv{ span<const volatile int>{src}, strided_bounds<1>{2, 1} };
#endif #endif