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:
Arne Elster 2021-12-19 18:20:11 +01:00 committed by Andreas Kling
parent 6a0cac7cdb
commit b7110c2a34

View file

@ -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 };