AK: Add Span to Array conversion function

This commit is contained in:
kleines Filmröllchen 2022-11-18 17:03:29 +01:00 committed by Andrew Kaster
parent 1943aef2cb
commit 026cc3d4b9
Notes: sideshowbarker 2024-07-17 03:10:59 +09:00

View file

@ -8,6 +8,8 @@
#include <AK/Iterator.h> #include <AK/Iterator.h>
#include <AK/Span.h> #include <AK/Span.h>
#include <AK/StdLibExtras.h>
#include <AK/TypedTransfer.h>
namespace AK { namespace AK {
@ -15,6 +17,15 @@ template<typename T, size_t Size>
struct Array { struct Array {
using ValueType = T; 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 const* data() const { return __data; }
[[nodiscard]] constexpr T* data() { return __data; } [[nodiscard]] constexpr T* data() { return __data; }