mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
AK: Add bytes() method to FixedArray.
This commit is contained in:
parent
d4fe63d2ce
commit
8e7dfebf11
1 changed files with 8 additions and 1 deletions
|
@ -26,6 +26,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Span.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
|
||||||
namespace AK {
|
namespace AK {
|
||||||
|
@ -33,7 +34,7 @@ namespace AK {
|
||||||
template<typename T>
|
template<typename T>
|
||||||
class FixedArray {
|
class FixedArray {
|
||||||
public:
|
public:
|
||||||
FixedArray() {}
|
FixedArray() { }
|
||||||
explicit FixedArray(size_t size)
|
explicit FixedArray(size_t size)
|
||||||
: m_size(size)
|
: m_size(size)
|
||||||
{
|
{
|
||||||
|
@ -86,6 +87,9 @@ public:
|
||||||
return m_elements;
|
return m_elements;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bytes bytes() { return { data(), size() }; }
|
||||||
|
ReadonlyBytes bytes() const { return { data(), size() }; }
|
||||||
|
|
||||||
T& operator[](size_t index)
|
T& operator[](size_t index)
|
||||||
{
|
{
|
||||||
ASSERT(index < m_size);
|
ASSERT(index < m_size);
|
||||||
|
@ -138,6 +142,9 @@ public:
|
||||||
ConstIterator begin() const { return ConstIterator(*this, 0); }
|
ConstIterator begin() const { return ConstIterator(*this, 0); }
|
||||||
ConstIterator end() const { return ConstIterator(*this, size()); }
|
ConstIterator end() const { return ConstIterator(*this, size()); }
|
||||||
|
|
||||||
|
operator Bytes() { return bytes(); }
|
||||||
|
operator ReadonlyBytes() const { return bytes(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t m_size { 0 };
|
size_t m_size { 0 };
|
||||||
T* m_elements { nullptr };
|
T* m_elements { nullptr };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue