From 106262f1ef68813e64854524634b19c37c4f1cdb Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Tue, 17 Nov 2015 19:01:46 -0800 Subject: [PATCH 1/5] Remove unnecessary workaround for max macro --- include/span.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/span.h b/include/span.h index a8d0542..7fd711c 100644 --- a/include/span.h +++ b/include/span.h @@ -39,12 +39,6 @@ #pragma push_macro("constexpr") #define constexpr /* nothing */ -// MSVC has the potential of bringing in headers where max is a macro -#ifdef max -#pragma push_macro("max") -#undef max -#endif - // VS 2013 workarounds #if _MSC_VER <= 1800 @@ -2046,10 +2040,6 @@ general_span_iterator operator+(typename general_span_iterator::diff #undef constexpr #pragma pop_macro("constexpr") -#ifdef max -#pragma pop_macro("max") -#endif - #if _MSC_VER <= 1800 #pragma warning(pop) From da75d0e7577aa01d3e307a6454ab500002d73b23 Mon Sep 17 00:00:00 2001 From: Matus Chochlik Date: Wed, 18 Nov 2015 17:43:59 +0100 Subject: [PATCH 2/5] Added explicit cast to size_type in span constructor This silences implicit sign conversion warnings when constructing span from containers which return size_t from size(). --- include/span.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/span.h b/include/span.h index 7fd711c..8a406ee 100644 --- a/include/span.h +++ b/include/span.h @@ -1267,7 +1267,7 @@ public: && std::is_convertible::value && std::is_same().size(), *std::declval().data())>, DataType>::value> > - constexpr span (Cont& cont) : span(static_cast(cont.data()), details::newBoundsHelper(cont.size())) + constexpr span (Cont& cont) : span(static_cast(cont.data()), details::newBoundsHelper(static_cast(cont.size()))) {} constexpr span(const span &) = default; From 73ec6886743ef1ab98e857e0db0197a2f3b2a4c8 Mon Sep 17 00:00:00 2001 From: Matus Chochlik Date: Thu, 19 Nov 2015 10:27:08 +0100 Subject: [PATCH 3/5] Made conversion of span<> to bool explicit --- include/span.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/span.h b/include/span.h index 8a406ee..dcce344 100644 --- a/include/span.h +++ b/include/span.h @@ -1434,7 +1434,7 @@ public: return m_pdata; } - constexpr operator bool() const noexcept + constexpr explicit operator bool() const noexcept { return m_pdata != nullptr; } @@ -1676,7 +1676,7 @@ public: return m_pdata; } - constexpr operator bool() const noexcept + constexpr explicit operator bool() const noexcept { return m_pdata != nullptr; } From c95eb57d3f43bf1ad19af79c463a5991a0bd7f6d Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Thu, 19 Nov 2015 12:02:06 -0800 Subject: [PATCH 4/5] Fixed conversion problem when creating strided_span from span and bounds --- include/span.h | 8 ++++++-- tests/span_tests.cpp | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/span.h b/include/span.h index dcce344..74a5e11 100644 --- a/include/span.h +++ b/include/span.h @@ -1610,8 +1610,12 @@ public: {} // from array view - template > - constexpr strided_span(span av, bounds_type bounds) : strided_span(av.data(), av.bounds().total_size(), std::move(bounds)) + template ::value, + typename Dummy = std::enable_if_t + > + constexpr strided_span(span av, bounds_type bounds) : strided_span(av.data(), av.bounds().total_size(), std::move(bounds)) {} // convertible diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 8a7c552..a78fe6e 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -333,7 +333,7 @@ SUITE(span_tests) CHECK(sav_c[1] == 2); #if _MSC_VER > 1800 - strided_span sav_v{ {src}, {2, 1} }; + strided_span sav_v{ src, {2, 1} }; #else strided_span sav_v{ span{src}, strided_bounds<1>{2, 1} }; #endif @@ -342,7 +342,7 @@ SUITE(span_tests) CHECK(sav_v[1] == 2); #if _MSC_VER > 1800 - strided_span sav_cv{ {src}, {2, 1} }; + strided_span sav_cv{ src, {2, 1} }; #else strided_span sav_cv{ span{src}, strided_bounds<1>{2, 1} }; #endif @@ -361,7 +361,7 @@ SUITE(span_tests) CHECK(sav_c[1] == 2); #if _MSC_VER > 1800 - strided_span sav_cv{ {src}, {2, 1} }; + strided_span sav_cv{ src, {2, 1} }; #else strided_span sav_cv{ span{src}, strided_bounds<1>{2, 1} }; #endif @@ -381,7 +381,7 @@ SUITE(span_tests) CHECK(sav_v[1] == 2); #if _MSC_VER > 1800 - strided_span sav_cv{ {src}, {2, 1} }; + strided_span sav_cv{ src, {2, 1} }; #else strided_span sav_cv{ span{src}, strided_bounds<1>{2, 1} }; #endif From e4d8d35af51aab9b072242aef0f57d8ce70625ab Mon Sep 17 00:00:00 2001 From: "Elron A. Yellin" Date: Fri, 20 Nov 2015 17:50:02 -0500 Subject: [PATCH 5/5] add as_span overload for basic_string which doesn't have nonconst .data() like other contiguous containers --- include/span.h | 8 ++++++++ tests/span_tests.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/include/span.h b/include/span.h index 74a5e11..2bf9d20 100644 --- a/include/span.h +++ b/include/span.h @@ -1568,6 +1568,14 @@ template constexpr auto as_span(Cont &&arr) -> std::enable_if_t>::value, span, dynamic_range>> = delete; +// from basic_string which doesn't have nonconst .data() member like other contiguous containers +template +constexpr auto as_span(std::basic_string &str) -> span +{ + fail_fast_assert(str.size() < PTRDIFF_MAX); + return {&str[0], static_cast(str.size())}; +} + template class strided_span { diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index a78fe6e..e5078af 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -203,6 +203,15 @@ SUITE(span_tests) overloaded_func(av3.as_span(dim<>(1), dim<3>(), dim<5>()), 't'); } + { + string str; + span strspan = as_span(str); + (void)strspan; + const string cstr; + span cstrspan = as_span(cstr); + (void)cstrspan; + } + { int a[3][4][5]; auto av = as_span(a);