aboutsummaryrefslogtreecommitdiff
path: root/src/span.h
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@protonmail.com>2020-04-30 11:16:39 +0200
committerWladimir J. van der Laan <laanwj@protonmail.com>2020-04-30 11:16:56 +0200
commit35ef3c15ef8263b79c6e8f002ceab270f08cd5a5 (patch)
tree04c9d58f6e5f7416e339f395f7684cf0bb80309e /src/span.h
parent63d5ed2fc45846ebab760764a3c07b1062212b3b (diff)
parentc31cbe7cfefc18123eb85ffb2ce509748435efde (diff)
downloadbitcoin-35ef3c15ef8263b79c6e8f002ceab270f08cd5a5.tar.xz
Merge #18591: Add C++17 build to Travis
c31cbe7cfefc18123eb85ffb2ce509748435efde Add C++17 test to Travis (Pieter Wuille) 7829685e27aae25efb32e07368175c8f664b2218 Add configure option for c++17 (Pieter Wuille) 0fbde488b24f62b4bbbde216647941dcac65c81a Support conversion between Spans of compatible types (Pieter Wuille) 7cbfebbf3df0d26f518811e0bfb7abf270c83e37 Update ax_cxx_compile_stdcxx.m4 (Pieter Wuille) Pull request description: This adds a `--enable-c++17` option to the configure script, fixes the only C++17 incompatibility (with a commit taken from #18468), and adds a Travis test for it. This is all off by default, and release builds remain C++11. It implements the first step of the plan in https://github.com/bitcoin/bitcoin/issues/16684. ACKs for top commit: elichai: tACK c31cbe7cfefc18123eb85ffb2ce509748435efde practicalswift: Tested ACK c31cbe7cfefc18123eb85ffb2ce509748435efde hebasto: ACK c31cbe7cfefc18123eb85ffb2ce509748435efde, tested on Linux Mint 19.3 both C++11 and C++17 modes. Compiled and passed tests locally. Tree-SHA512: a4b00776dbceef9c12abbb404c6bcd48f7916ce24c8c7a14116355f64e817578b7fcddbedd5ce435322319d1e4de43429b68553f4d96d970c308fe3e3e59b9d1
Diffstat (limited to 'src/span.h')
-rw-r--r--src/span.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/span.h b/src/span.h
index 664ea8d4c6..73b37e35f3 100644
--- a/src/span.h
+++ b/src/span.h
@@ -25,6 +25,23 @@ public:
constexpr Span(C* data, std::ptrdiff_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.
+ *
+ * Specifically, if a pointer to an array of type O can be implicitly converted to a pointer to an array of type
+ * C, then permit implicit conversion of Span<O> to Span<C>. This matches the behavior of the corresponding
+ * C++20 std::span constructor.
+ *
+ * For example this means that a Span<T> can be converted into a Span<const T>.
+ */
+ template <typename O, typename std::enable_if<std::is_convertible<O (*)[], C (*)[]>::value, int>::type = 0>
+ constexpr Span(const Span<O>& other) noexcept : m_data(other.m_data), m_size(other.m_size) {}
+
+ /** Default copy constructor. */
+ constexpr Span(const Span&) noexcept = default;
+
+ /** Default assignment operator. */
+ Span& operator=(const Span& other) noexcept = default;
+
constexpr C* data() const noexcept { return m_data; }
constexpr C* begin() const noexcept { return m_data; }
constexpr C* end() const noexcept { return m_data + m_size; }
@@ -44,6 +61,8 @@ public:
friend constexpr bool operator<=(const Span& a, const Span& b) noexcept { return !(b < a); }
friend constexpr bool operator>(const Span& a, const Span& b) noexcept { return (b < a); }
friend constexpr bool operator>=(const Span& a, const Span& b) noexcept { return !(a < b); }
+
+ template <typename O> friend class Span;
};
/** Create a span to a container exposing data() and size().