mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
span: (almost) match std::span's constructor behavior
c++20's draft of std::span no longer includes move constructors.
This commit is contained in:
parent
f32f7e907a
commit
62733fee87
1 changed files with 21 additions and 2 deletions
23
src/span.h
23
src/span.h
|
@ -28,6 +28,14 @@ class Span
|
||||||
C* m_data;
|
C* m_data;
|
||||||
std::size_t m_size;
|
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:
|
public:
|
||||||
constexpr Span() noexcept : m_data(nullptr), m_size(0) {}
|
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.
|
* 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).
|
* 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>
|
template <typename V>
|
||||||
constexpr Span(V&& v) noexcept : m_data(v.data()), m_size(v.size()) {}
|
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* data() const noexcept { return m_data; }
|
||||||
constexpr C* begin() const noexcept { return m_data; }
|
constexpr C* begin() const noexcept { return m_data; }
|
||||||
|
|
Loading…
Reference in a new issue