mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Add Span to Array conversion function
This commit is contained in:
parent
1943aef2cb
commit
026cc3d4b9
Notes:
sideshowbarker
2024-07-17 03:10:59 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/026cc3d4b9 Pull-request: https://github.com/SerenityOS/serenity/pull/16054 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/idispatch
1 changed files with 11 additions and 0 deletions
11
AK/Array.h
11
AK/Array.h
|
@ -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; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue