From b7110c2a3446ec745b90d3cd6b6b3f8fc1bc1f86 Mon Sep 17 00:00:00 2001 From: Arne Elster Date: Sun, 19 Dec 2021 18:20:11 +0100 Subject: [PATCH] AK: Add constructor to create Span from Array It's a convenience constructor. But it also seems more consistent to allow a Span being made from both raw and managed arrays. --- AK/Span.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/AK/Span.h b/AK/Span.h index 78bcc4c753..bd379d0e6c 100644 --- a/AK/Span.h +++ b/AK/Span.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -33,6 +34,21 @@ public: { } + template + ALWAYS_INLINE constexpr Span(Array& array) + : m_values(array.data()) + , m_size(size) + { + } + + template + requires(IsConst) + ALWAYS_INLINE constexpr Span(Array const& array) + : m_values(array.data()) + , m_size(size) + { + } + protected: T* m_values { nullptr }; size_t m_size { 0 };