From 0e14b5b3069dce8c8cc9275447105f31d707f51f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E9=9B=A8=E5=9F=B9?= Date: Fri, 22 Apr 2016 10:22:41 +0800 Subject: [PATCH] Add as_span(iterator start, iterator last). --- include/span.h | 6 ++++++ tests/span_tests.cpp | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/span.h b/include/span.h index a612983..3685143 100644 --- a/include/span.h +++ b/include/span.h @@ -1688,6 +1688,12 @@ constexpr auto as_span(T* const& ptr, dim... args) details::static_as_span_helper>(args..., details::Sep{})}; } +template +constexpr Span as_span(contiguous_span_iterator start, contiguous_span_iterator last) +{ + return { &*start, static_cast(last - start)}; +} + template constexpr auto as_span(T* arr, std::ptrdiff_t len) -> typename details::SpanArrayTraits::type diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 8b39639..ef0fd44 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -1193,7 +1193,7 @@ SUITE(span_tests) } { - int a[3][4][5]; + int a[3][4][5] = {}; auto av = as_span(a); const int(*b)[4][5]; b = a; @@ -1209,6 +1209,9 @@ SUITE(span_tests) auto dv = as_span(vec); (void) dv; + auto av2 = as_span(av.begin(), av.end()); + CHECK(av2 == av); + #ifdef CONFIRM_COMPILATION_ERRORS auto dv2 = as_span(std::move(vec)); #endif