diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-01-02 11:19:01 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-01-02 11:13:40 +0100 |
commit | fa65bbf217b725ada35107b4ad646d250228355c (patch) | |
tree | 7b42706ae01568d34b551f08a2d5cf284c892ddf | |
parent | 8b5a4de904b414fb3a818732cd0a2c90b91bc275 (diff) |
span: Add BytePtr helper
-rw-r--r-- | src/span.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/span.h b/src/span.h index 47390a5bb2..b627b993c2 100644 --- a/src/span.h +++ b/src/span.h @@ -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> |