|
|
constexpr | small_vec () noexcept |
| | Constructs an empty vector in the inline state.
|
| |
|
constexpr | ~small_vec () |
| | Destroys elements and frees any heap block.
|
| |
| constexpr void | push_back (const T &value) |
| | Appends value, growing to the heap if the inline buffer is full.
|
| |
| constexpr void | assign (std::size_t count, const T &value) |
| | Resizes to count copies of value.
|
| |
| constexpr void | ensure_size (std::size_t count) |
| | Ensures at least count live elements without re-filling or shrinking.
|
| |
| constexpr std::size_t | size () const noexcept |
| | Returns the number of elements.
|
| |
| constexpr bool | empty () const noexcept |
| | Returns true if empty.
|
| |
| constexpr T & | operator[] (std::size_t i) noexcept |
| | Returns reference to the element at i.
|
| |
| constexpr const T & | operator[] (std::size_t i) const noexcept |
| | Returns const reference to the element at i.
|
| |
|
constexpr void | clear () noexcept |
| | Removes all elements (capacity and heap state unchanged).
|
| |
| constexpr T & | back () noexcept |
| | Returns reference to the last element. Precondition: the vector is non-empty.
|
| |
| constexpr const T & | back () const noexcept |
| | Returns const reference to the last element. Precondition: the vector is non-empty.
|
| |
|
constexpr void | pop_back () noexcept |
| | Removes the last element. Precondition: the vector is non-empty.
|
| |
| constexpr void | reserve (std::size_t new_capacity) |
| | Ensures capacity for at least new_capacity elements (heap-backed).
|
| |
| constexpr | small_vec (small_vec &&other) noexcept |
| | Move constructor: steals other's heap block or moves inline elements.
|
| |
| constexpr small_vec & | operator= (small_vec &&other) noexcept |
| | Move assignment.
|
| |
| constexpr | small_vec (const small_vec &other) |
| | Copy constructor.
|
| |
| constexpr small_vec & | operator= (const small_vec &other) |
| | Copy assignment.
|
| |
|
|
constexpr void | refresh_data () noexcept |
| | Refreshes data_ to the active storage base (run time only).
|
| |
| constexpr T * | inline_data () noexcept |
| | Returns pointer to the inline buffer.
|
| |
| constexpr const T * | inline_data () const noexcept |
| | Returns const pointer to the inline buffer.
|
| |
| template<bool Move> |
| constexpr void | transfer_range (const T *src, std::size_t count, T *dest) |
| | Copies or moves count elements from src to dest.
|
| |
| template<bool Move> |
| constexpr void | transfer_inline_from (const small_vec &other) |
| | Transfers other's inline elements into this vector's inline buffer.
|
| |
| constexpr void | adopt_heap (T *p) noexcept |
| | Points the union at p, making Storage::heap_ptr the active member.
|
| |
| constexpr void | revert_to_inline () noexcept |
| | Makes the inline buffer the active union member again, after the heap block is gone.
|
| |
|
constexpr void | cleanup () noexcept |
| | Frees the heap block, if any; no element destructor runs (T is trivially destructible).
|
| |
|
constexpr void | extend_capacity () |
| | Doubles the capacity (saturating), spilling to the heap as needed.
|
| |
template<typename T, std::size_t InlineCapacity>
class real::detail::small_vec< T, InlineCapacity >
Small-buffer-optimized vector for the dynamic hot paths: up to InlineCapacity elements inline, spilling to the heap beyond that.
- Note
T must be trivially destructible (static_assert): no element destructor ever runs.
- Warning
- At run time the inline buffer is UNINITIALIZED (value-initialized only under constant evaluation, in the
Storage constructor). Every element's lifetime begins with std::construct_at before it is read, and reads stay within [0, size_); a new accessor must keep that write-before-read order. Only MemorySanitizer detects a breach (the CI sanitize leg is ASan/UBSan): run an MSan build when changing element access.
- Template Parameters
-
| T | Element type. |
| InlineCapacity | Number of elements held inline before spilling. |
template<typename T , std::size_t InlineCapacity>
|
|
inlinestaticconstexprprivate |
Obtains storage for n elements from the allocator the current regime allows.
Constant evaluation cannot call a raw allocation operator, so it uses std::allocator, whose transient blocks must all be released before the evaluation ends (cleanup does).
- Parameters
-
- Returns
- Uninitialized storage for
n elements.
template<typename T , std::size_t InlineCapacity>
|
|
inlineconstexprprivatenoexcept |
Makes the inline buffer the active union member again, after the heap block is gone.
Required wherever a spilled vector returns inline (a moved-from source, an assignment target): a later constant-evaluated inline_data read would otherwise touch an inactive member.