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
Notes:
sideshowbarker
2024-07-17 18:13:35 +09:00
Author: https://github.com/standardexe Commit: https://github.com/SerenityOS/serenity/commit/b7110c2a34 Pull-request: https://github.com/SerenityOS/serenity/pull/12749
1 changed files with 16 additions and 0 deletions
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…
Add table
Reference in a new issue