diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2020-03-29 16:31:03 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2020-05-12 14:12:46 -0700 |
commit | 1f790a1147ad9a5fe06987d84b6cd71f91cbec4b (patch) | |
tree | 320deb12f1d446ca83369d16e4083e1c6b249fe5 | |
parent | 8da1e43b63cb36759eeb1fcfd6768163265c44e2 (diff) | |
download | bitcoin-1f790a1147ad9a5fe06987d84b6cd71f91cbec4b.tar.xz |
Make Span size type unsigned
This matches a change in the C++20 std::span proposal.
-rw-r--r-- | src/span.h | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/span.h b/src/span.h index 73b37e35f3..31e9fba12c 100644 --- a/src/span.h +++ b/src/span.h @@ -18,11 +18,12 @@ template<typename C> class Span { C* m_data; - std::ptrdiff_t m_size; + std::size_t m_size; public: constexpr Span() noexcept : m_data(nullptr), m_size(0) {} - constexpr Span(C* data, std::ptrdiff_t size) noexcept : m_data(data), m_size(size) {} + constexpr Span(C* data, std::size_t size) noexcept : m_data(data), m_size(size) {} + constexpr Span(C* data, C* end) noexcept : m_data(data), m_size(end - data) {} /** Implicit conversion of spans between compatible types. @@ -47,13 +48,13 @@ public: constexpr C* end() const noexcept { return m_data + m_size; } constexpr C& front() const noexcept { return m_data[0]; } constexpr C& back() const noexcept { return m_data[m_size - 1]; } - constexpr std::ptrdiff_t size() const noexcept { return m_size; } - constexpr C& operator[](std::ptrdiff_t pos) const noexcept { return m_data[pos]; } + constexpr std::size_t size() const noexcept { return m_size; } + constexpr C& operator[](std::size_t pos) const noexcept { return m_data[pos]; } - constexpr Span<C> subspan(std::ptrdiff_t offset) const noexcept { return Span<C>(m_data + offset, m_size - offset); } - constexpr Span<C> subspan(std::ptrdiff_t offset, std::ptrdiff_t count) const noexcept { return Span<C>(m_data + offset, count); } - constexpr Span<C> first(std::ptrdiff_t count) const noexcept { return Span<C>(m_data, count); } - constexpr Span<C> last(std::ptrdiff_t count) const noexcept { return Span<C>(m_data + m_size - count, count); } + constexpr Span<C> subspan(std::size_t offset) const noexcept { return Span<C>(m_data + offset, m_size - offset); } + constexpr Span<C> subspan(std::size_t offset, std::size_t count) const noexcept { return Span<C>(m_data + offset, count); } + constexpr Span<C> first(std::size_t count) const noexcept { return Span<C>(m_data, count); } + constexpr Span<C> last(std::size_t count) const noexcept { return Span<C>(m_data + m_size - count, count); } friend constexpr bool operator==(const Span& a, const Span& b) noexcept { return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin()); } friend constexpr bool operator!=(const Span& a, const Span& b) noexcept { return !(a == b); } |