diff options
author | Cory Fields <cory-nospam-@coryfields.com> | 2020-06-26 13:21:13 -0400 |
---|---|---|
committer | Cory Fields <cory-nospam-@coryfields.com> | 2020-06-29 13:51:24 -0400 |
commit | 62733fee874bfe7e833e71380eb8efd6a3126fbd (patch) | |
tree | 124769a7c0627dd97b166ba7f32d80248f5ebfef /src/span.h | |
parent | f32f7e907a5eb73e880c567c699569081608ed7a (diff) |
span: (almost) match std::span's constructor behavior
c++20's draft of std::span no longer includes move constructors.
Diffstat (limited to 'src/span.h')
-rw-r--r-- | src/span.h | 23 |
1 files 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 <class T> + struct is_Span_int : public std::false_type {}; + template <class T> + struct is_Span_int<Span<T>> : public std::true_type {}; + template <class T> + struct is_Span : public is_Span_int<typename std::remove_cv<T>::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 <typename V, typename std::enable_if<(std::is_const<C>::value || std::is_lvalue_reference<V>::value) && std::is_convertible<typename std::remove_pointer<decltype(std::declval<V&>().data())>::type (*)[], C (*)[]>::value && std::is_convertible<decltype(std::declval<V&>().size()), std::size_t>::value, int>::type = 0> - constexpr Span(V&& v) noexcept : m_data(v.data()), m_size(v.size()) {} + template <typename V> + constexpr Span(V& other, + typename std::enable_if<!is_Span<V>::value && + std::is_convertible<typename std::remove_pointer<decltype(std::declval<V&>().data())>::type (*)[], C (*)[]>::value && + std::is_convertible<decltype(std::declval<V&>().size()), std::size_t>::value, std::nullptr_t>::type = nullptr) + : m_data(other.data()), m_size(other.size()){} + + template <typename V> + constexpr Span(const V& other, + typename std::enable_if<!is_Span<V>::value && + std::is_convertible<typename std::remove_pointer<decltype(std::declval<const V&>().data())>::type (*)[], C (*)[]>::value && + std::is_convertible<decltype(std::declval<const V&>().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; } |