mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
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.
This commit is contained in:
parent
6a0cac7cdb
commit
b7110c2a34
1 changed files with 16 additions and 0 deletions
16
AK/Span.h
16
AK/Span.h
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Array.h>
|
||||||
#include <AK/Assertions.h>
|
#include <AK/Assertions.h>
|
||||||
#include <AK/Iterator.h>
|
#include <AK/Iterator.h>
|
||||||
#include <AK/TypedTransfer.h>
|
#include <AK/TypedTransfer.h>
|
||||||
|
@ -33,6 +34,21 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<size_t size>
|
||||||
|
ALWAYS_INLINE constexpr Span(Array<T, size>& array)
|
||||||
|
: m_values(array.data())
|
||||||
|
, m_size(size)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
template<size_t size>
|
||||||
|
requires(IsConst<T>)
|
||||||
|
ALWAYS_INLINE constexpr Span(Array<T, size> const& array)
|
||||||
|
: m_values(array.data())
|
||||||
|
, m_size(size)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
T* m_values { nullptr };
|
T* m_values { nullptr };
|
||||||
size_t m_size { 0 };
|
size_t m_size { 0 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue