|
Zth (libzth)
|
A simple std::vector, which can contain Prealloc without heap allocation.
More...
#include <util.h>
Public Types | |
| enum | |
| typedef T | value_type |
| typedef Allocator | allocator_type |
| typedef std::vector< value_type, allocator_type > | vector_type |
Public Member Functions | |
| constexpr | small_vector () noexcept |
| Default ctor. More... | |
| ~small_vector () | |
| Dtor. More... | |
| value_type & | operator[] (size_t index) noexcept |
| Access an element. More... | |
| value_type const & | operator[] (size_t index) const noexcept |
| Access an element. More... | |
| value_type & | front () noexcept |
| Access the first element. More... | |
| value_type const & | front () const noexcept |
| Access the first element. More... | |
| value_type & | back () noexcept |
| Access the last element. More... | |
| value_type const & | back () const noexcept |
| Access the last element. More... | |
| value_type * | data () noexcept |
| Access the data array. More... | |
| value_type const * | data () const noexcept |
| Access the data array. More... | |
| bool | empty () const noexcept |
| Check if the vector is empty. More... | |
| size_t | size () const noexcept |
| Return the number of elements stored in the vector. More... | |
| void | reserve (size_t new_cap) |
| Reserve memory to accommodate at least the given number of elements. More... | |
| size_t | capacity () const noexcept |
| Return the number of elements for which memory is currently reesrved. More... | |
| void | clear () noexcept |
| Erase all elements from the vector. More... | |
| void | clear_and_release () noexcept |
| Erase all elements from the vector and release all heap memory. More... | |
| void | push_back (value_type const &v) |
| Append an element to the vector using the copy constructor. More... | |
| template<class... Args> | |
| void | emplace_back (Args &&... args) |
| Append an element to the vector by construct in-place. More... | |
| void | pop_back () noexcept |
| Remove the last element. More... | |
| void | resize (size_t count, value_type const &x=value_type()) |
| Resize the number of elements in the vector. More... | |
Protected Member Functions | |
| bool | is_small () const noexcept |
| Check if the current vector still fits in the internal buffer. More... | |
| value_type * | array () noexcept |
| Interpret buffer as the small vector. More... | |
| value_type const * | array () const noexcept |
| Interpret buffer as the small vector. More... | |
| vector_type & | vector () noexcept |
| Interpret buffer as an std::vector. More... | |
| vector_type const & | vector () const noexcept |
| Interpret buffer as an std::vector. More... | |
| void | make_vector (size_t new_cap) |
| Make sure the std::vector is used as storage. More... | |
A simple std::vector, which can contain Prealloc without heap allocation.
When the internal buffer is exhausted, the vector grows automatically into an std::vector, using heap memory after all.
In all cases, the elements are stored in contiguous memory, like guaranteed by std::vector. Upon a push_back(), underlying memory may be reallocated to accommodate the new element, which renders previous pointers invalid.
| T | the type of elements to contain |
| Prealloc | the minimum number of elements to contain without using heap |
| Allocator | the allocator to use for std::vector |
| typedef Allocator zth::small_vector< T, Prealloc, Allocator >::allocator_type |
| typedef T zth::small_vector< T, Prealloc, Allocator >::value_type |
| typedef std::vector<value_type, allocator_type> zth::small_vector< T, Prealloc, Allocator >::vector_type |
| anonymous enum |
|
inlineconstexprnoexcept |
|
inline |
|
inlineprotectednoexcept |
|
inlineprotectednoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlineprotectednoexcept |
|
inlineprotected |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
Reserve memory to accommodate at least the given number of elements.
| std::bad_alloc | when allocation fails |
|
inline |
|
inlinenoexcept |
|
inlineprotectednoexcept |
|
inlineprotectednoexcept |