From 026cc3d4b9876b396e4e656f3752a5c012f0a872 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 18 Nov 2022 17:03:29 +0100 Subject: [PATCH] AK: Add Span to Array conversion function --- AK/Array.h | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 #include +#include +#include namespace AK { @@ -15,6 +17,15 @@ template struct Array { using ValueType = T; + // This is a static function because constructors mess up Array's POD-ness. + static Array from_span(Span span) + { + Array array; + VERIFY(span.size() == Size); + TypedTransfer::copy(array.data(), span.data(), Size); + return array; + } + [[nodiscard]] constexpr T const* data() const { return __data; } [[nodiscard]] constexpr T* data() { return __data; }