From de54b8784ca59e5c98cec4ac3b84075adcb22f63 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Sun, 2 Jan 2022 11:19:01 +0100 Subject: [PATCH] partial bitcoin#23438: Use spans of std::byte in serialize includes: - fa65bbf217b725ada35107b4ad646d250228355c --- src/span.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/span.h b/src/span.h index 3d96269768..b4bf6325dc 100644 --- a/src/span.h +++ b/src/span.h @@ -237,16 +237,21 @@ T& SpanPopBack(Span& span) return back; } +//! Convert a data pointer to a std::byte data pointer. +//! Where possible, please use the safer AsBytes helpers. +inline const std::byte* BytePtr(const void* data) { return reinterpret_cast(data); } +inline std::byte* BytePtr(void* data) { return reinterpret_cast(data); } + // From C++20 as_bytes and as_writeable_bytes template Span AsBytes(Span s) noexcept { - return {reinterpret_cast(s.data()), s.size_bytes()}; + return {BytePtr(s.data()), s.size_bytes()}; } template Span AsWritableBytes(Span s) noexcept { - return {reinterpret_cast(s.data()), s.size_bytes()}; + return {BytePtr(s.data()), s.size_bytes()}; } template