![]() |
Implementation of a dynamic vector with small vector optimization.The SmallVector class template is a hybrid data structure between a static array and a dynamic vector. It provides static, in-place memory for up to N elements of type T, but can grow beyond this size by allocating dynamic memory via its allocator of type A. More...
#include <SmallVector.h>
Inherits A.
Classes | |
struct | Uninitialized |
Definition of the nested auxiliary struct Uninitialized. More... | |
Public Types | |
using | ElementType = T |
Type of the vector elements. | |
using | Pointer = T * |
Pointer to a non-constant vector element. | |
using | ConstPointer = const T * |
Pointer to a constant vector element. | |
using | Reference = T & |
Reference to a non-constant vector element. | |
using | ConstReference = const T & |
Reference to a constant vector element. | |
using | Iterator = T * |
Iterator over non-constant elements. | |
using | ConstIterator = const T * |
Iterator over constant elements. | |
Public Member Functions | |
template<typename U > | |
SmallVector< T, N, A > & | operator= (initializer_list< U > list) |
List assignment to all vector elements. More... | |
Destructor | |
~SmallVector () | |
The destructor for DynamicVector. | |
Data access functions | |
Reference | operator[] (size_t index) noexcept |
Subscript operator for the direct access to the vector elements. More... | |
ConstReference | operator[] (size_t index) const noexcept |
Subscript operator for the direct access to the vector elements. More... | |
Reference | at (size_t index) |
Checked access to the vector elements. More... | |
ConstReference | at (size_t index) const |
Checked access to the vector elements. More... | |
Pointer | data () noexcept |
Low-level data access to the vector elements. More... | |
ConstPointer | data () const noexcept |
Low-level data access to the vector elements. More... | |
Iterator | begin () noexcept |
Returns an iterator to the first element of the small vector. More... | |
ConstIterator | begin () const noexcept |
Returns an iterator to the first element of the small vector. More... | |
ConstIterator | cbegin () const noexcept |
Returns an iterator to the first element of the small vector. More... | |
Iterator | end () noexcept |
Returns an iterator just past the last element of the small vector. More... | |
ConstIterator | end () const noexcept |
Returns an iterator just past the last element of the small vector. More... | |
ConstIterator | cend () const noexcept |
Returns an iterator just past the last element of the small vector. More... | |
Assignment operators | |
template<typename U > | |
SmallVector & | operator= (initializer_list< U > list) |
SmallVector & | operator= (const SmallVector &rhs) |
Copy assignment operator for SmallVector. More... | |
SmallVector & | operator= (SmallVector &&rhs) |
Move assignment operator for SmallVector. More... | |
Private Types | |
enum | : size_t |
Adjustment of the size of the static storage. | |
Private Attributes | |
Member variables | |
byte_t | v_ [NN] |
The static storage. | |
T * | begin_ |
Pointer to the beginning of the currently used storage. | |
T * | end_ |
Pointer to the end of the currently used storage. | |
T * | final_ |
Pointer to the very end of the currently used storage. | |
Constructors | |
SmallVector (const A &alloc=A()) | |
The (default) constructor for SmallVector. More... | |
SmallVector (size_t n, const A &alloc=A()) | |
Constructor for a vector of size n. No element initialization is performed! More... | |
SmallVector (size_t n, const T &init, const A &alloc=A()) | |
Constructor for a vector of size n. More... | |
template<typename InputIt > | |
SmallVector (InputIt first, InputIt last, const A &alloc=A()) | |
Constructor for a range of elements. More... | |
template<typename U > | |
SmallVector (initializer_list< U > list, const A &alloc=A()) | |
List initialization of all vector elements. More... | |
SmallVector (const SmallVector &sv) | |
The copy constructor for SmallVector. More... | |
SmallVector (SmallVector &&sv) | |
The move constructor for SmallVector. More... | |
SmallVector (size_t n, const A &alloc, Uninitialized) | |
Auxiliary constructor for SmallVector. More... | |
Utility functions | |
bool | empty () const noexcept |
Returns whether the vector is empty. More... | |
size_t | size () const noexcept |
Returns the current size/dimension of the small vector. More... | |
size_t | capacity () const noexcept |
Returns the maximum capacity of the small vector. More... | |
void | clear () |
Clearing the vector. More... | |
void | resize (size_t n) |
Changing the size of the vector. More... | |
void | resize (size_t n, const T &value) |
Changing the size of the vector. More... | |
void | reserve (size_t n) |
Setting the minimum capacity of the vector. More... | |
void | shrinkToFit () |
Requesting the removal of unused capacity. More... | |
void | pushBack (const T &value) |
Adding an element to the end of the small vector. More... | |
void | pushBack (T &&value) |
Adding an element to the end of the small vector. More... | |
Iterator | insert (Iterator pos, const T &value) |
Inserting an element at the specified position into the small vector. More... | |
Iterator | insert (Iterator pos, T &&value) |
Inserting an element at the specified position into the small vector. More... | |
Iterator | erase (Iterator pos) |
Erasing an element from the small vector. More... | |
Iterator | erase (Iterator first, Iterator last) |
Erasing a range of elements from the small vector. More... | |
void | swap (SmallVector &sv) noexcept(IsNothrowMoveConstructible< T >::value) |
Swapping the contents of two small vectors. More... | |
bool | isDynamic () const noexcept |
Returns whether the small vector uses its dynamic storage. More... | |
Implementation of a dynamic vector with small vector optimization.
The SmallVector class template is a hybrid data structure between a static array and a dynamic vector. It provides static, in-place memory for up to N elements of type T, but can grow beyond this size by allocating dynamic memory via its allocator of type A.
|
inlineexplicit |
The (default) constructor for SmallVector.
alloc | Allocator for all memory allocations of this container. |
|
inlineexplicit |
Constructor for a vector of size n. No element initialization is performed!
n | The initial size of the vector. |
alloc | Allocator for all memory allocations of this container. |
|
inlineexplicit |
Constructor for a vector of size n.
n | The initial size of the vector. |
init | The initial value of the vector elements. |
alloc | Allocator for all memory allocations of this container. |
All vector elements are initialized with the specified value.
|
inlineexplicit |
Constructor for a range of elements.
first | Iterator to the be first element of the input range. |
last | Iterator to the element one past the last element of the input range. |
alloc | Allocator for all memory allocations of this container. |
|
inlineexplicit |
List initialization of all vector elements.
list | The initializer list. |
alloc | Allocator for all memory allocations of this container. |
This constructor provides the option to explicitly initialize the elements of the small vector within a constructor call:
The vector is sized according to the size of the initializer list and all its elements are copy initialized by the elements of the given initializer list.
|
inline |
The copy constructor for SmallVector.
sv | The small vector to be copied. |
|
inline |
The move constructor for SmallVector.
sv | The small vector to be moved into this instance. |
|
inlineexplicitprivate |
Auxiliary constructor for SmallVector.
n | The initial size of the vector. |
alloc | Allocator for all memory allocations of this container. |
|
inline |
Checked access to the vector elements.
index | Access index. The index has to be in the range ![]() |
std::out_of_range | Invalid small vector access index. |
In contrast to the subscript operator this function always performs a check of the given access index.
|
inline |
Checked access to the vector elements.
index | Access index. The index has to be in the range ![]() |
std::out_of_range | Invalid small vector access index. |
In contrast to the subscript operator this function always performs a check of the given access index.
|
inlinenoexcept |
Returns an iterator to the first element of the small vector.
|
inlinenoexcept |
Returns an iterator to the first element of the small vector.
|
inlinenoexcept |
Returns the maximum capacity of the small vector.
|
inlinenoexcept |
Returns an iterator to the first element of the small vector.
|
inlinenoexcept |
Returns an iterator just past the last element of the small vector.
|
inline |
|
inlinenoexcept |
Low-level data access to the vector elements.
This function returns a pointer to the internal storage of the small vector.
|
inlinenoexcept |
Low-level data access to the vector elements.
This function returns a pointer to the internal storage of the small vector.
|
inlinenoexcept |
Returns whether the vector is empty.
|
inlinenoexcept |
Returns an iterator just past the last element of the small vector.
|
inlinenoexcept |
Returns an iterator just past the last element of the small vector.
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::erase | ( | Iterator | pos | ) |
Erasing an element from the small vector.
pos | Iterator to the element to be erased. |
This function erases an element from the small vector.
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::erase | ( | Iterator | first, |
Iterator | last | ||
) |
Erasing a range of elements from the small vector.
first | Iterator to first element to be erased. |
last | Iterator just past the last element to be erased. |
This function erases a range of elements from the small vector.
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::insert | ( | Iterator | pos, |
const T & | value | ||
) |
Inserting an element at the specified position into the small vector.
pos | The position of the new element. |
value | The value of the element to be inserted. |
SmallVector< T, N, A >::Iterator blaze::SmallVector< T, N, A >::insert | ( | Iterator | pos, |
T && | value | ||
) |
Inserting an element at the specified position into the small vector.
pos | The position of the new element. |
value | The value of the element to be inserted. |
|
inlineprivatenoexcept |
Returns whether the small vector uses its dynamic storage.
|
inline |
Copy assignment operator for SmallVector.
rhs | Vector to be copied. |
The vector is resized according to the given small vector and initialized as a copy of this vector.
|
inline |
Move assignment operator for SmallVector.
rhs | The vector to be moved into this instance. |
|
inline |
List assignment to all vector elements.
list | The initializer list. |
This assignment operator offers the option to directly assign to all elements of the small vector by means of an initializer list:
The vector is resized according to the size of the initializer list and all its elements are assigned the values from the given initializer list.
|
inlinenoexcept |
Subscript operator for the direct access to the vector elements.
index | Access index. The index has to be in the range ![]() |
This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access index.
|
inlinenoexcept |
Subscript operator for the direct access to the vector elements.
index | Access index. The index has to be in the range ![]() |
This function only performs an index check in case BLAZE_USER_ASSERT() is active. In contrast, the at() function is guaranteed to perform a check of the given access index.
void blaze::SmallVector< T, N, A >::pushBack | ( | const T & | value | ) |
Adding an element to the end of the small vector.
value | The element to be added to the end of the small vector. |
void blaze::SmallVector< T, N, A >::pushBack | ( | T && | value | ) |
Adding an element to the end of the small vector.
value | The element to be added to the end of the small vector. |
void blaze::SmallVector< T, N, A >::reserve | ( | size_t | n | ) |
Setting the minimum capacity of the vector.
n | The new minimum capacity of the vector. |
This function increases the capacity of the vector to at least n elements. The current values of the vector elements are preserved.
void blaze::SmallVector< T, N, A >::resize | ( | size_t | n | ) |
Changing the size of the vector.
n | The new size of the vector. |
This function resizes the vector using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the vector is too small. New vector elements are not initialized!
void blaze::SmallVector< T, N, A >::resize | ( | size_t | n, |
const T & | value | ||
) |
Changing the size of the vector.
n | The new size of the vector. |
value | The initial value of new vector elements. |
This function resizes the vector using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the vector is too small. New vector elements are initialized to value!
void blaze::SmallVector< T, N, A >::shrinkToFit | ( | ) |
Requesting the removal of unused capacity.
This function minimizes the capacity of the vector by removing unused capacity. Please note that in case a reallocation occurs, all iterators (including end() iterators), all pointers and references to elements of this vector are invalidated.
|
inlinenoexcept |
Returns the current size/dimension of the small vector.
|
noexcept |
Swapping the contents of two small vectors.
sv | The small vector to be swapped. |
This function swaps the contents of two small vectors. Please note that this function is only guaranteed to not throw an exception if the move constructor of the underlying data type T is guaranteed to be noexcept.