5#include <egg/core/Heap.hh>
44 std::copy(span.begin(), span.end(),
m_data);
51 std::copy(rhs.begin(), rhs.end(),
m_data);
71 std::copy(rhs.begin(), rhs.end(),
m_data);
117 [[nodiscard]]
const T &
front()
const {
129 [[nodiscard]]
const T &
back()
const {
134 [[nodiscard]] T *begin() {
138 [[nodiscard]] T *end() {
142 [[nodiscard]]
const T *begin()
const {
146 [[nodiscard]]
const T *end()
const {
156 [[nodiscard]]
size_t size()
const {
161 [[nodiscard]] std::span<const T>
view()
const {
192 allocate(rhs.m_capacity);
193 for (size_t i = 0; i < rhs.m_size; ++i) {
202 : m_data(rhs.m_data), m_size(rhs.m_size), m_capacity(rhs.m_capacity) {
203 rhs.m_data =
nullptr;
215 for (
size_t i = 0; i < rhs.m_size; ++i) {
232 m_capacity = rhs.m_capacity;
234 rhs.m_data =
nullptr;
253 new (m_data + m_size++) T(obj);
262 new (m_data + m_size++) T(std::move(obj));
270 template <
typename... Args>
273 new (m_data + m_size++) T(std::forward<Args>(args)...);
280 m_data[--m_size].~T();
298 [[nodiscard]]
bool full()
const {
299 return m_size == m_capacity;
305 return m_data && m_capacity != 0;
310 [[nodiscard]]
size_t size()
const {
338 return m_data[m_size - 1];
345 return m_data[m_size - 1];
352 ASSERT(idx < m_size);
360 ASSERT(idx < m_size);
382 return m_data + m_size;
387 const T *
end() const noexcept {
389 return m_data + m_size;
399 EGG::egg_free(m_data);
408 m_data =
static_cast<T *
>(
409 EGG::egg_alloc(
sizeof(T) *
capacity,
static_cast<s32
>(
alignof(T))));
T & push_back(const T &obj)
Copies a new element into the array.
fixed_vector(fixed_vector &&rhs)
Move constructor.
size_t capacity() const
Gets the maximum number of elements that can exist in the array.
bool empty() const
Checks if there are no existing elements in the array.
fixed_vector & operator=(fixed_vector &&rhs)
Move assignment operator.
const T * end() const noexcept
Iterator for the end of the existing array.
const T & back() const
Gets the last existing element in the array.
fixed_vector()
Non-initializing constructor.
T & push_back(T &&obj)
Moves a new element into the array.
bool initialized() const
Checks if the array exists and if the capacity is non-zero.
fixed_vector(const fixed_vector &rhs)
Copy constructor.
T & operator[](size_t idx)
Indexes the array. Validates that the object exists.
fixed_vector & operator=(const fixed_vector &rhs)
Copy assignment operator.
const T * begin() const noexcept
Iterator for the beginning of the existing array.
T * end() noexcept
Iterator for the end of the existing array.
T & emplace_back(Args &&...args)
Creates a new element in-place in the array.
T & back()
Gets the last existing element in the array.
~fixed_vector()
Destructor.
void pop_back()
Deletes the last existing element from the array.
void destroy()
Destroys existing elements and frees the buffer, resetting to an uninitialized state.
bool full() const
Checks if all elements exist in the array.
const T & operator[](size_t idx) const
Indexes the array. Validates that the object exists.
T * begin() noexcept
Iterator for the beginning of the existing array.
size_t size() const
Gets the number of existing elements in the array.
const T & front() const
Gets the first element in the array.
T & front()
Gets the first element in the array.
fixed_vector(size_t capacity)
Initializing constructor.
void allocate(size_t capacity)
Allocates the array.
void reserve(size_t capacity)
Initializes the vector with the provided capacity.
owning_span()
Uninitialized buffer.
const T & back() const
Retrieves the last element in the buffer.
owning_span & operator=(const owning_span &rhs)
Copy assignment operator.
const T & front() const
Retrieves the first element in the buffer.
T & back()
Retrieves the last element in the buffer.
owning_span(const owning_span &rhs)
Copy constructor.
bool empty() const
Returns true if the buffer is uninitialized.
T & front()
Retrieves the first element in the buffer.
size_t size() const
Returns the number of elements that fit in the buffer.
T * m_data
Pointer to the underlying buffer.
~owning_span()
Destroys the underlying buffer on teardown.
owning_span(size_t count)
Allocates a buffer of T elements. Does not initialize any elements.
owning_span & operator=(owning_span &&rhs)
Move assignment operator.
size_t m_size
The number of T elements that fit in the buffer.
const T & operator[](size_t idx) const
Indexes into the underlying buffer.
T & operator[](size_t idx)
Indexes into the underlying buffer.
owning_span(owning_span &&rhs)
Move constructor.
owning_span(const std::span< const T > &span)
Performs a deep copy from a std::span of const T.
std::span< const T > view() const
Returns a read-only view of the entire buffer.