Skip to content

Engine → Core → stable_vector.h

stable_vector

Syntax

template <typename T, usize ChunkSize = 64> class stable_vector

Constructors

AccessSignatureDescription
publicstable_vector() = default;
publicstable_vector( const stable_vector &other);
publicstable_vector( stable_vector &&other) noexcept;

Destructors

AccessSignatureDescription
public~stable_vector();

Variables

AccessNameTypeDefaultDescription
publicCHUNK_SIZEstatic constexpr usizeChunkSizeElements per chunk.
privatemChunksstd::vector<T *>{}
privatemSizeusize0

Functions

Public

at

[[nodiscard]] T &at(
    usize index) noexcept;

Bounds-checked access in every configuration. An out-of-range index is a fatal programmer error (asserts, then terminates), never an exception.

[[nodiscard]] const T &at(
    usize index) const noexcept;

back

[[nodiscard]] T &back() noexcept;
[[nodiscard]] const T &back() const noexcept;

begin

[[nodiscard]] iterator begin() noexcept;
[[nodiscard]] const_iterator begin() const noexcept;

capacity

[[nodiscard]] usize capacity() const noexcept;

Elements that fit in the allocated chunks.

cbegin

[[nodiscard]] const_iterator cbegin() const noexcept;

cend

[[nodiscard]] const_iterator cend() const noexcept;

chunk_count

[[nodiscard]] usize chunk_count() const noexcept;

clear

void clear() noexcept;

Destroys every element; chunks are kept so capacity() is unchanged.

emplace_back

template <typename... Args> T &emplace_back(
    Args &&...args);

Constructs an element at the end and returns a reference that stays valid until the element is destroyed (pop_back, clear, destruction). Never moves other elements.

empty

[[nodiscard]] bool empty() const noexcept;

end

[[nodiscard]] iterator end() noexcept;
[[nodiscard]] const_iterator end() const noexcept;

front

[[nodiscard]] T &front() noexcept;
[[nodiscard]] const T &front() const noexcept;

pop_back

void pop_back() noexcept;

Destroys the last element. Asserts when empty. Chunks are kept.

push_back

T &push_back(
    const T &value);
T &push_back(
    T &&value);

reserve

void reserve(
    usize count);

Allocates chunks so that count elements fit without further allocation.

shrink_to_fit

void shrink_to_fit() noexcept;

Frees chunks that hold no element.

size

[[nodiscard]] usize size() const noexcept;

Private

allocate_chunk

[[nodiscard]] static T *allocate_chunk();

deallocate_chunk

static void deallocate_chunk(
    T *chunk) noexcept;

release_chunks

void release_chunks() noexcept;

slot_at

[[nodiscard]] T *slot_at(
    usize index) const noexcept;

Operator Overloads

Public

operator=

stable_vector &operator=(
    const stable_vector &other);
stable_vector &operator=(
    stable_vector &&other) noexcept;

operator[]

[[nodiscard]] T &operator[](
    usize index) noexcept;
[[nodiscard]] const T &operator[](
    usize index) const noexcept;