Engine → Core → small_vector.h
small_vector
| Type | Class |
| Namespace | conjure::core |
| Include File Path | engine/include/conjure/core/containers/small_vector.h |
| Source File Path | N/A |
| API ↗ | Containers |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | small_vector() noexcept; | |
| public | explicit small_vector(
usize count); | count value-initialised elements. |
| public | small_vector(
usize count,
const T &value); | count copies of value. |
| public | small_vector(
std::initializer_list<T> values); | |
| public | template <std::input_iterator Iterator> small_vector(
Iterator first,
Iterator last); | |
| public | explicit small_vector(
std::span<const T> values); | |
| public | small_vector(
const small_vector &other); | |
| public | small_vector(
small_vector &&other) noexcept; |
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~small_vector(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| public | INLINE_ | static constexpr usize | N | Elements stored inside the object before the heap is used. |
| public | IS_ | static constexpr bool | std:: | True when elements are relocated with memcpy instead of move + destroy. |
| private | mCapacity | usize | N | |
| private | mData | T * | nullptr | |
| private | mInline | inline_storage | {} | |
| private | mSize | usize | 0 |
Functions
Public
assign
assignvoid assign(
usize count,
const T &value);Replaces the contents with count copies of value. value may refer to an element of this vector.
template <std::input_iterator Iterator> void assign(
Iterator first,
Iterator last);Replaces the contents with a copy of the range.
at
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
back[[nodiscard]] T &back() noexcept;[[nodiscard]] const T &back() const noexcept;capacity
capacity[[nodiscard]] usize capacity() const noexcept;cbegin
cbegin[[nodiscard]] const_iterator cbegin() const noexcept;cend
cend[[nodiscard]] const_iterator cend() const noexcept;clear
clearvoid clear() noexcept;Destroys every element; keeps the current storage.
data
data[[nodiscard]] T *data() noexcept;[[nodiscard]] const T *data() const noexcept;emplace
emplacetemplate <typename... Args> iterator emplace(
const_iterator position,
Args &&...args);Constructs an element before position (which may be end()). Arguments may refer to existing elements. Requires a move-assignable T unless T is trivially copyable.
emplace_back
emplace_backtemplate <typename... Args> T &emplace_back(
Args &&...args);Constructs an element at the end and returns it. Arguments may refer to existing elements; they are read before any reallocation.
empty
empty[[nodiscard]] bool empty() const noexcept;erase
eraseiterator erase(
const_iterator position);Erases the element at position. Returns the iterator following it.
iterator erase(
const_iterator first,
const_iterator last);Erases [first, last). Returns the iterator following the last erased element.
front
front[[nodiscard]] T &front() noexcept;[[nodiscard]] const T &front() const noexcept;insert
insertiterator insert(
const_iterator position,
const T &value);Inserts a copy of value before position. Returns an iterator to the new element.
iterator insert(
const_iterator position,
T &&value);template <std::input_iterator Iterator> iterator insert(
const_iterator position,
Iterator first,
Iterator last);Inserts a copy of the range before position (which may be end()). The range must not alias this vector. Returns an iterator to the first inserted element. Single-pass (input) iterators are collected into a temporary vector first.
iterator insert(
const_iterator position,
std::initializer_list<T> values);is_inline
is_inline[[nodiscard]] bool is_inline() const noexcept;True while the elements live inside the object (no heap allocation).
max_size
max_size[[nodiscard]] static constexpr usize max_size() noexcept;pop_back
pop_backvoid pop_back() noexcept;Destroys the last element. Asserts when empty.
push_back
push_backvoid push_back(
const T &value);Appends a copy of value. value may refer to an element of this vector.
void push_back(
T &&value);Appends by move.
rbegin
rbegin[[nodiscard]] reverse_iterator rbegin() noexcept;[[nodiscard]] const_reverse_iterator rbegin() const noexcept;rend
rend[[nodiscard]] reverse_iterator rend() noexcept;[[nodiscard]] const_reverse_iterator rend() const noexcept;reserve
reservevoid reserve(
usize count);Makes room for at least count elements without constructing any.
resize
resizevoid resize(
usize count);Grows with value-initialised elements or shrinks by destroying the tail.
void resize(
usize count,
const T &value);Grows with copies of value or shrinks by destroying the tail. value may refer to an element of this vector.
shrink_to_fit
shrink_to_fitvoid shrink_to_fit();Moves the elements back inline when they fit, or trims heap capacity to size().
size
size[[nodiscard]] usize size() const noexcept;swap
swapvoid swap(
small_vector &other) noexcept;Exchanges contents with another vector of the same type.
Private
allocate_storage
allocate_storage[[nodiscard]] static T *allocate_storage(
usize count);append_range
append_rangetemplate <typename Iterator> void append_range(
Iterator first,
Iterator last);assign_range
assign_rangetemplate <typename Iterator> void assign_range(
Iterator first,
Iterator last);deallocate_storage
deallocate_storagestatic void deallocate_storage(
T *storage,
usize count) noexcept;destroy_range
destroy_rangestatic void destroy_range(
T *first,
usize count) noexcept;emplace_with_growth
emplace_with_growthtemplate <typename... Args> T *emplace_with_growth(
usize index,
Args &&...args);Reallocates leaving an uninitialised hole at index and constructs the new element there first, so arguments aliasing old elements are still intact when read.
index_of
index_of[[nodiscard]] usize index_of(
const_iterator position) const noexcept;inline_data
inline_data[[nodiscard]] T *inline_data() noexcept;[[nodiscard]] const T *inline_data() const noexcept;open_gap
open_gapShifts [index, size) right by count leaving uninitialised storage in the gap. mSize is not updated; the caller fills the gap and adds count.
reallocate
reallocatevoid reallocate(
usize newCapacity);release_heap
release_heapvoid release_heap() noexcept;relocate_range
relocate_rangestatic void relocate_range(
T *source,
T *destination,
usize count) noexcept;Moves count elements from source to uninitialised destination and ends the lifetime of the sources. The ranges must not overlap.
take_from
take_fromvoid take_from(
small_vector &other) noexcept;Steals the heap buffer of other or relocates its inline elements. other ends up empty and inline. This vector must be empty and inline.
Operator Overloads
Public
operator<=>
operator<=>[[nodiscard]] auto operator<=>(
const small_vector &other) const requires detail::synth_three_way_comparable<T>;Lexicographical ordering like std::vector's: uses T's operator<=> when it has one and falls back to operator< (weak ordering) otherwise. Absent for element types that are not even less-than comparable.
operator=
operator=small_vector &operator=(
const small_vector &other);small_vector &operator=(
small_vector &&other) noexcept;small_vector &operator=(
std::initializer_list<T> values);operator==
operator==[[nodiscard]] bool operator==(
const small_vector &other) const;