Add as_span(iterator start, iterator last).

This commit is contained in:
刘雨培 2016-04-22 10:22:41 +08:00
parent a9f865900d
commit 0e14b5b306
2 changed files with 10 additions and 1 deletions

View File

@ -1688,6 +1688,12 @@ constexpr auto as_span(T* const& ptr, dim<Dimensions>... args)
details::static_as_span_helper<static_bounds<Dimensions...>>(args..., details::Sep{})}; details::static_as_span_helper<static_bounds<Dimensions...>>(args..., details::Sep{})};
} }
template<typename Span>
constexpr Span as_span(contiguous_span_iterator<Span> start, contiguous_span_iterator<Span> last)
{
return { &*start, static_cast<typename Span::size_type>(last - start)};
}
template <typename T> template <typename T>
constexpr auto as_span(T* arr, std::ptrdiff_t len) -> constexpr auto as_span(T* arr, std::ptrdiff_t len) ->
typename details::SpanArrayTraits<T, dynamic_range>::type typename details::SpanArrayTraits<T, dynamic_range>::type

View File

@ -1193,7 +1193,7 @@ SUITE(span_tests)
} }
{ {
int a[3][4][5]; int a[3][4][5] = {};
auto av = as_span(a); auto av = as_span(a);
const int(*b)[4][5]; const int(*b)[4][5];
b = a; b = a;
@ -1209,6 +1209,9 @@ SUITE(span_tests)
auto dv = as_span(vec); auto dv = as_span(vec);
(void) dv; (void) dv;
auto av2 = as_span(av.begin(), av.end());
CHECK(av2 == av);
#ifdef CONFIRM_COMPILATION_ERRORS #ifdef CONFIRM_COMPILATION_ERRORS
auto dv2 = as_span(std::move(vec)); auto dv2 = as_span(std::move(vec));
#endif #endif