0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

span: Add BytePtr helper

This commit is contained in:
MarcoFalke 2022-01-02 11:19:01 +01:00
parent 8b5a4de904
commit fa65bbf217
No known key found for this signature in database
GPG key ID: CE2B75697E69A548

View file

@ -243,16 +243,21 @@ T& SpanPopBack(Span<T>& 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<const std::byte*>(data); }
inline std::byte* BytePtr(void* data) { return reinterpret_cast<std::byte*>(data); }
// From C++20 as_bytes and as_writeable_bytes
template <typename T>
Span<const std::byte> AsBytes(Span<T> s) noexcept
{
return {reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()};
return {BytePtr(s.data()), s.size_bytes()};
}
template <typename T>
Span<std::byte> AsWritableBytes(Span<T> s) noexcept
{
return {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()};
return {BytePtr(s.data()), s.size_bytes()};
}
template <typename V>