diff options
author | kleines Filmröllchen <filmroellchen@serenityos.org> | 2022-11-18 17:03:29 +0100 |
---|---|---|
committer | Andrew Kaster <andrewdkaster@gmail.com> | 2022-12-15 00:21:00 -0700 |
commit | 026cc3d4b9876b396e4e656f3752a5c012f0a872 (patch) | |
tree | 8b857a8f6c3af5b7d81dc182fae337f60464b498 /AK | |
parent | 1943aef2cbde161d7e70ad538645ac805acbe734 (diff) | |
download | serenity-026cc3d4b9876b396e4e656f3752a5c012f0a872.zip |
AK: Add Span to Array conversion function
Diffstat (limited to 'AK')
-rw-r--r-- | AK/Array.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/AK/Array.h b/AK/Array.h index bf41eb6018..a12949cad2 100644 --- a/AK/Array.h +++ b/AK/Array.h @@ -8,6 +8,8 @@ #include <AK/Iterator.h> #include <AK/Span.h> +#include <AK/StdLibExtras.h> +#include <AK/TypedTransfer.h> namespace AK { @@ -15,6 +17,15 @@ template<typename T, size_t Size> struct Array { using ValueType = T; + // This is a static function because constructors mess up Array's POD-ness. + static Array from_span(Span<T> span) + { + Array array; + VERIFY(span.size() == Size); + TypedTransfer<T>::copy(array.data(), span.data(), Size); + return array; + } + [[nodiscard]] constexpr T const* data() const { return __data; } [[nodiscard]] constexpr T* data() { return __data; } |