diff options
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; } |