12 template<
typename T, std::
unsigned_
integral SizeT, SizeT MaxSize>
requires std::equality_comparable<T> && std::movable<T>
15 using iterator =
typename std::array<T, MaxSize>::iterator;
21 if (m_Size >= MaxSize) {
24 m_Data[m_Size] = value;
29 template<
typename... Args>
requires std::constructible_from<T, Args...>
32 throw std::length_error(
"Cannot emplace into a full PackedArray");
35 std::construct_at(&m_Data[m_Size], std::forward<Args>(args)...);
37 return m_Data[m_Size++];
45 auto it = std::find(
begin(),
end(), value);
50 if (it !=
end() - 1) {
51 *it = std::move(m_Data[m_Size - 1]);
56 if constexpr (!std::is_trivially_destructible_v<T>) {
57 std::destroy_at(&m_Data[m_Size]);
64 if (index <= m_Size) {
65 return remove(m_Data[index]);
77 [[nodiscard]] SizeT
size()
const {
81 [[nodiscard]]
constexpr SizeT
capacity()
const {
85 [[nodiscard]]
bool empty()
const {
89 [[nodiscard]]
bool full()
const {
90 return m_Size >= MaxSize;
100 [[nodiscard]] T&
at(SizeT index) {
101 if (index >= m_Size) {
102 throw std::out_of_range(
"PackedArray index out of range");
104 return m_Data[index];
107 const T&
at(SizeT index)
const {
108 if (index >= m_Size) {
109 throw std::out_of_range(
"PackedArray index out of range");
111 return m_Data[index];
119 std::array<T, MaxSize> m_Data{};
typename std::array< T, MaxSize >::iterator iterator
bool remove(const SizeT index)
bool remove(const T &value)
const T & at(SizeT index) const
bool push_back(const T &value)
const_iterator cbegin() const
const T & operator[](SizeT index) const
T & emplace(Args &&... args)
constexpr SizeT capacity() const
typename std::array< T, MaxSize >::const_iterator const_iterator
T & operator[](SizeT index)
const_iterator cend() const
Core systems of the engine are here.