AK: Add bytes() method to FixedArray.

This commit is contained in:
asynts 2020-08-12 21:15:11 +02:00 committed by Andreas Kling
parent d4fe63d2ce
commit 8e7dfebf11
Notes: sideshowbarker 2024-07-19 03:35:14 +09:00

View file

@ -26,6 +26,7 @@
#pragma once
#include <AK/Span.h>
#include <AK/Vector.h>
namespace AK {
@ -33,7 +34,7 @@ namespace AK {
template<typename T>
class FixedArray {
public:
FixedArray() {}
FixedArray() { }
explicit FixedArray(size_t size)
: m_size(size)
{
@ -86,6 +87,9 @@ public:
return m_elements;
}
Bytes bytes() { return { data(), size() }; }
ReadonlyBytes bytes() const { return { data(), size() }; }
T& operator[](size_t index)
{
ASSERT(index < m_size);
@ -138,6 +142,9 @@ public:
ConstIterator begin() const { return ConstIterator(*this, 0); }
ConstIterator end() const { return ConstIterator(*this, size()); }
operator Bytes() { return bytes(); }
operator ReadonlyBytes() const { return bytes(); }
private:
size_t m_size { 0 };
T* m_elements { nullptr };