From 62733fee874bfe7e833e71380eb8efd6a3126fbd Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 26 Jun 2020 13:21:13 -0400 Subject: [PATCH] span: (almost) match std::span's constructor behavior c++20's draft of std::span no longer includes move constructors. --- src/span.h | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/span.h b/src/span.h index 4931507719..78c30fa553 100644 --- a/src/span.h +++ b/src/span.h @@ -28,6 +28,14 @@ class Span C* m_data; std::size_t m_size; + template + struct is_Span_int : public std::false_type {}; + template + struct is_Span_int> : public std::true_type {}; + template + struct is_Span : public is_Span_int::type>{}; + + public: constexpr Span() noexcept : m_data(nullptr), m_size(0) {} @@ -78,8 +86,19 @@ public: * To prevent surprises, only Spans for constant value types are supported when passing in temporaries. * Note that this restriction does not exist when converting arrays or other Spans (see above). */ - template ::value || std::is_lvalue_reference::value) && std::is_convertible().data())>::type (*)[], C (*)[]>::value && std::is_convertible().size()), std::size_t>::value, int>::type = 0> - constexpr Span(V&& v) noexcept : m_data(v.data()), m_size(v.size()) {} + template + constexpr Span(V& other, + typename std::enable_if::value && + std::is_convertible().data())>::type (*)[], C (*)[]>::value && + std::is_convertible().size()), std::size_t>::value, std::nullptr_t>::type = nullptr) + : m_data(other.data()), m_size(other.size()){} + + template + constexpr Span(const V& other, + typename std::enable_if::value && + std::is_convertible().data())>::type (*)[], C (*)[]>::value && + std::is_convertible().size()), std::size_t>::value, std::nullptr_t>::type = nullptr) + : m_data(other.data()), m_size(other.size()){} constexpr C* data() const noexcept { return m_data; } constexpr C* begin() const noexcept { return m_data; }