diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-04-02 13:00:05 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-03 15:53:49 +0200 |
commit | 5c045b693427f35b13b40f586fa63bd1d08e06ed (patch) | |
tree | 3212c35c48fa4ccc0f53d1cd313b83cf33d59b55 /AK/Span.h | |
parent | f7960ffbe3b3d686afb0982608818c5341fe057b (diff) | |
download | serenity-5c045b693427f35b13b40f586fa63bd1d08e06ed.zip |
AK: Add templated Span<u8> and Span<u8 const> constructors for C-arrays
This helper constructor exists on the unspecialized Span<T> class also,
and is convenient for e.g. creating Bytes from:
u8 buffer[64];
Bytes bytes { buffer };
Diffstat (limited to 'AK/Span.h')
-rw-r--r-- | AK/Span.h | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -64,12 +64,20 @@ public: , m_size(size) { } + ALWAYS_INLINE Span(void* values, size_t size) : m_values(reinterpret_cast<u8*>(values)) , m_size(size) { } + template<size_t size> + ALWAYS_INLINE constexpr Span(u8 (&values)[size]) + : m_values(values) + , m_size(size) + { + } + protected: u8* m_values { nullptr }; size_t m_size { 0 }; @@ -85,17 +93,26 @@ public: , m_size(size) { } + ALWAYS_INLINE Span(void const* values, size_t size) : m_values(reinterpret_cast<u8 const*>(values)) , m_size(size) { } + ALWAYS_INLINE Span(char const* values, size_t size) : m_values(reinterpret_cast<u8 const*>(values)) , m_size(size) { } + template<size_t size> + ALWAYS_INLINE constexpr Span(u8 const (&values)[size]) + : m_values(values) + , m_size(size) + { + } + protected: u8 const* m_values { nullptr }; size_t m_size { 0 }; |