mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-07 00:19:27 +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
16
AK/Span.h
16
AK/Span.h
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Array.h>
|
||||
#include <AK/Assertions.h>
|
||||
#include <AK/Iterator.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:
|
||||
T* m_values { nullptr };
|
||||
size_t m_size { 0 };
|
||||
|
|
Loading…
Reference in a new issue