template<typename T, size_t InlineCapacity = 4>
class ultralight::Vector< T, InlineCapacity >
A std::vector-like container with small buffer optimization and ABI-safe allocation.
This container can be used safely in public API boundaries where std::vector cannot, because STL types are not guaranteed to be ABI-compatible across different compilers, standard library implementations, or even different build configurations.
All heap allocation is routed through UltralightCore's exported allocator functions (ul_malloc / ul_free), ensuring that memory allocated by the library is always freed by the library – regardless of which runtime the caller was built with.
Small Buffer Optimization (SBO)
When InlineCapacity > 0 (the default), the first N elements are stored inline within the Vector object itself, avoiding heap allocation for common small lists. Once the size exceeds InlineCapacity, the Vector transparently switches to heap storage.
Type support
Works with both trivially-copyable types (uses memcpy/realloc fast paths) and non-trivial types like RefPtr<T> (proper construction, destruction, and move semantics).
Example
A std::vector-like container with small buffer optimization and ABI-safe allocation.
Definition Vector.h:88
void push_back(const T &value)
Definition Vector.h:368
friend class Vector
Definition Vector.h:95
- Template Parameters
-
| T | Element type. |
| InlineCapacity | Number of elements stored inline before heap allocation (default 4). Use 0 for pure heap storage with no inline overhead. |
|
| | Vector ()=default |
| | Construct an empty vector.
|
| | Vector (size_t count) |
| | Construct a vector with count value-initialized elements.
|
| | Vector (size_t count, const T &value) |
| | Construct a vector with count copies of value.
|
| | Vector (std::initializer_list< T > init) |
| template<typename InputIt, typename = typename std::enable_if<!std::is_integral<InputIt>::value>::type> |
| | Vector (InputIt first, InputIt last) |
| | Vector (const Vector &other) |
| template<size_t OtherInline> |
| | Vector (const Vector< T, OtherInline > &other) |
| | Vector (Vector &&other) noexcept(InlineCapacity==0||std::is_nothrow_move_constructible< T >::value) |
| template<size_t OtherInline> |
| | Vector (Vector< T, OtherInline > &&other) noexcept(std::is_nothrow_move_constructible< T >::value) |
| | ~Vector () |
| Vector & | operator= (const Vector &other) |
| template<size_t OtherInline> |
| Vector & | operator= (const Vector< T, OtherInline > &other) |
| Vector & | operator= (Vector &&other) noexcept(InlineCapacity==0||std::is_nothrow_move_constructible< T >::value) |
| template<size_t OtherInline> |
| Vector & | operator= (Vector< T, OtherInline > &&other) noexcept(std::is_nothrow_move_constructible< T >::value) |
| Vector & | operator= (std::initializer_list< T > init) |
| void | assign (size_t count, const T &value) |
| template<typename InputIt, typename = typename std::enable_if<!std::is_integral<InputIt>::value>::type> |
| void | assign (InputIt first, InputIt last) |
| void | assign (std::initializer_list< T > init) |
| T & | operator[] (size_t index) |
| | Access element by index.
|
| const T & | operator[] (size_t index) const |
| T & | at (size_t index) |
| | Access element by index with bounds checking (asserts in debug builds).
|
| const T & | at (size_t index) const |
| T & | front () |
| const T & | front () const |
| T & | back () |
| const T & | back () const |
| T * | data () |
| const T * | data () const |
| iterator | begin () |
| const_iterator | begin () const |
| const_iterator | cbegin () const |
| iterator | end () |
| const_iterator | end () const |
| const_iterator | cend () const |
| bool | empty () const |
| size_t | size () const |
| size_t | capacity () const |
| | Returns the number of elements that can be held without allocating.
|
| void | reserve (size_t min_capacity) |
| | Ensure capacity for at least min_capacity elements, allocating if necessary.
|
| void | shrink_to_fit () |
| | Reduce capacity to fit the current size.
|
| void | clear () |
| void | push_back (const T &value) |
| void | push_back (T &&value) |
| template<typename... Args> |
| T & | emplace_back (Args &&... args) |
| | Construct an element in-place at the end of the vector.
|
| void | unchecked_append (const T &value) |
| | Append an element without checking capacity.
|
| template<typename... Args> |
| T & | unchecked_emplace_back (Args &&... args) |
| | Construct an element in-place at the end without checking capacity.
|
| void | pop_back () |
| T | take_last () |
| | Remove the last element and return it by move.
|
| iterator | insert (const_iterator pos, const T &value) |
| iterator | insert (const_iterator pos, T &&value) |
| template<typename... Args> |
| iterator | emplace (const_iterator pos, Args &&... args) |
| iterator | erase (const_iterator pos) |
| iterator | erase (const_iterator first, const_iterator last) |
| void | resize (size_t count) |
| void | resize (size_t count, const T &value) |
| void | swap (Vector &other) |
| template<size_t OtherInline> |
| void | append_vector (const Vector< T, OtherInline > &other) |
| | Append all elements from another vector.
|
| template<size_t OtherInline> |
| void | append_vector (Vector< T, OtherInline > &&other) |
| | Move-append all elements from another vector, leaving it empty.
|