diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-11-13 00:01:06 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-12-20 15:35:58 +0100 |
commit | 35a996490200126e72775398fa3d6daa0ec4f435 (patch) | |
tree | 065bc639ff3a2bd4e06e63b2a6c6255f509ddbb0 /asl/span.hpp | |
parent | ac47be51b79f4c3e49656870e135453eefe759ea (diff) |
Introduce byte, use span<byte> on io Writer
Diffstat (limited to 'asl/span.hpp')
-rw-r--r-- | asl/span.hpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/asl/span.hpp b/asl/span.hpp index e0db059..7135509 100644 --- a/asl/span.hpp +++ b/asl/span.hpp @@ -171,8 +171,26 @@ public: ASL_ASSERT(sub_size >= 0 && sub_size <= size()); return span<T>{ data() + size() - sub_size, sub_size }; } - - // @Todo as_(mutable_)bytes }; +template<is_object T, isize_t kSize> +inline span<const byte> as_bytes(span<T, kSize> s) +{ + return span<const byte>( + reinterpret_cast<const byte*>(s.data()), + s.size_bytes()); +} + +template<is_object T, isize_t kSize> +inline span<byte> as_mutable_bytes(span<T, kSize> s) + requires (!is_const<T>) +{ + return span<byte>( + reinterpret_cast<byte*>(s.data()), + s.size_bytes()); +} + +template<is_object T, isize_t kSize> +span(T (&)[kSize]) -> span<T, kSize>; + } // namespace asl |