![]() |
Blaze 3.9
|
Implementation of a dynamic array with small array optimization. More...
#include <SmallArray.h>
Inherits SmallArrayData< T, N >, and std::allocator< T >.
Classes | |
struct | Uninitialized |
Definition of the nested auxiliary struct Uninitialized. More... | |
Public Member Functions | |
template<typename U > | |
SmallArray< T, N, A > & | operator= (initializer_list< U > list) |
List assignment to all array elements. More... | |
Destructor | |
~SmallArray () | |
The destructor for SmallArray. | |
Data access functions | |
Reference | operator[] (size_t index) noexcept |
Subscript operator for the direct access to the array elements. More... | |
ConstReference | operator[] (size_t index) const noexcept |
Subscript operator for the direct access to the array elements. More... | |
Reference | at (size_t index) |
Checked access to the array elements. More... | |
ConstReference | at (size_t index) const |
Checked access to the array elements. More... | |
Pointer | data () noexcept |
Low-level data access to the array elements. More... | |
ConstPointer | data () const noexcept |
Low-level data access to the array elements. More... | |
Iterator | begin () noexcept |
Returns an iterator to the first element of the small array. More... | |
ConstIterator | begin () const noexcept |
Returns an iterator to the first element of the small array. More... | |
ConstIterator | cbegin () const noexcept |
Returns an iterator to the first element of the small array. More... | |
Iterator | end () noexcept |
Returns an iterator just past the last element of the small array. More... | |
ConstIterator | end () const noexcept |
Returns an iterator just past the last element of the small array. More... | |
ConstIterator | cend () const noexcept |
Returns an iterator just past the last element of the small array. More... | |
Assignment operators | |
template<typename U > | |
SmallArray & | operator= (initializer_list< U > list) |
SmallArray & | operator= (const SmallArray &rhs) |
Copy assignment operator for SmallArray. More... | |
SmallArray & | operator= (SmallArray &&rhs) |
Move assignment operator for SmallArray. More... | |
Constructors | |
SmallArray (const A &alloc=A()) | |
The (default) constructor for SmallArray. More... | |
SmallArray (size_t n, const A &alloc=A()) | |
Constructor for an array of size n. No element initialization is performed! More... | |
SmallArray (size_t n, const T &init, const A &alloc=A()) | |
Constructor for an array of size n. More... | |
template<typename InputIt > | |
SmallArray (InputIt first, InputIt last, const A &alloc=A()) | |
Constructor for a range of elements. More... | |
template<typename U > | |
SmallArray (initializer_list< U > list, const A &alloc=A()) | |
List initialization of all array elements. More... | |
SmallArray (const SmallArray &sa) | |
The copy constructor for SmallArray. More... | |
SmallArray (SmallArray &&sa) | |
The move constructor for SmallArray. More... | |
SmallArray (size_t n, const A &alloc, Uninitialized) | |
Auxiliary constructor for SmallArray. More... | |
Utility functions | |
bool | empty () const noexcept |
Returns whether the array is empty. More... | |
size_t | size () const noexcept |
Returns the current size/dimension of the small array. More... | |
size_t | capacity () const noexcept |
Returns the maximum capacity of the small array. More... | |
void | clear () |
Clearing the array. More... | |
void | resize (size_t n) |
Changing the size of the array. More... | |
void | resize (size_t n, const T &value) |
Changing the size of the array. More... | |
void | reserve (size_t n) |
Setting the minimum capacity of the array. More... | |
void | shrinkToFit () |
Requesting the removal of unused capacity. More... | |
void | pushBack (const T &value) |
Adding an element to the end of the small array. More... | |
void | pushBack (T &&value) |
Adding an element to the end of the small array. More... | |
Iterator | insert (Iterator pos, const T &value) |
Inserting an element at the specified position into the small array. More... | |
Iterator | insert (Iterator pos, T &&value) |
Inserting an element at the specified position into the small array. More... | |
Iterator | erase (Iterator pos) |
Erasing an element from the small array. More... | |
Iterator | erase (Iterator first, Iterator last) |
Erasing a range of elements from the small array. More... | |
void | swap (SmallArray &sa) noexcept(IsNothrowMoveConstructible_v< T >) |
Swapping the contents of two small arrays. More... | |
bool | isDynamic () const noexcept |
Returns whether the small array uses its dynamic storage. More... | |
Implementation of a dynamic array with small array optimization.
The SmallArray class template is a hybrid data structure between a static array and a dynamic array. 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 SmallArray.
alloc | Allocator for all memory allocations of this container. |
|
inlineexplicit |
Constructor for an array of size n. No element initialization is performed!
n | The initial size of the array. |
alloc | Allocator for all memory allocations of this container. |
|
inline |
Constructor for an array of size n.
n | The initial size of the array. |
init | The initial value of the array elements. |
alloc | Allocator for all memory allocations of this container. |
All array elements are initialized with the specified value.
|
inline |
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. |
|
inline |
List initialization of all array 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 array within a constructor call:
The array 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 SmallArray.
sa | The small array to be copied. |
|
inline |
The move constructor for SmallArray.
sa | The small array to be moved into this instance. |
|
inlineprivate |
Auxiliary constructor for SmallArray.
n | The initial size of the array. |
alloc | Allocator for all memory allocations of this container. |
|
inline |
Checked access to the array elements.
index | Access index. The index has to be in the range ![]() |
std::out_of_range | Invalid small array access index. |
In contrast to the subscript operator this function always performs a check of the given access index.
|
inline |
Checked access to the array elements.
index | Access index. The index has to be in the range ![]() |
std::out_of_range | Invalid small array 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 array.
|
inlinenoexcept |
Returns an iterator to the first element of the small array.
|
inlinenoexcept |
Returns the maximum capacity of the small array.
|
inlinenoexcept |
Returns an iterator to the first element of the small array.
|
inlinenoexcept |
Returns an iterator just past the last element of the small array.
|
inline |
|
inlinenoexcept |
Low-level data access to the array elements.
This function returns a pointer to the internal storage of the small array.
|
inlinenoexcept |
Low-level data access to the array elements.
This function returns a pointer to the internal storage of the small array.
|
inlinenoexcept |
Returns whether the array is empty.
|
inlinenoexcept |
Returns an iterator just past the last element of the small array.
|
inlinenoexcept |
Returns an iterator just past the last element of the small array.
SmallArray< T, N, A >::Iterator blaze::SmallArray< T, N, A >::erase | ( | Iterator | first, |
Iterator | last | ||
) |
Erasing a range of elements from the small array.
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 array.
SmallArray< T, N, A >::Iterator blaze::SmallArray< T, N, A >::erase | ( | Iterator | pos | ) |
Erasing an element from the small array.
pos | Iterator to the element to be erased. |
This function erases an element from the small array.
SmallArray< T, N, A >::Iterator blaze::SmallArray< T, N, A >::insert | ( | Iterator | pos, |
const T & | value | ||
) |
Inserting an element at the specified position into the small array.
pos | The position of the new element. |
value | The value of the element to be inserted. |
SmallArray< T, N, A >::Iterator blaze::SmallArray< T, N, A >::insert | ( | Iterator | pos, |
T && | value | ||
) |
Inserting an element at the specified position into the small array.
pos | The position of the new element. |
value | The value of the element to be inserted. |
|
inlineprivatenoexcept |
Returns whether the small array uses its dynamic storage.
|
inline |
Copy assignment operator for SmallArray.
rhs | Array to be copied. |
The array is resized according to the given small array and initialized as a copy of this array.
|
inline |
List assignment to all array elements.
list | The initializer list. |
This assignment operator offers the option to directly assign to all elements of the small array by means of an initializer list:
The array is resized according to the size of the initializer list and all its elements are assigned the values from the given initializer list.
|
inline |
Move assignment operator for SmallArray.
rhs | The array to be moved into this instance. |
|
inlinenoexcept |
Subscript operator for the direct access to the array 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 array 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::SmallArray< T, N, A >::pushBack | ( | const T & | value | ) |
Adding an element to the end of the small array.
value | The element to be added to the end of the small array. |
void blaze::SmallArray< T, N, A >::pushBack | ( | T && | value | ) |
Adding an element to the end of the small array.
value | The element to be added to the end of the small array. |
void blaze::SmallArray< T, N, A >::reserve | ( | size_t | n | ) |
Setting the minimum capacity of the array.
n | The new minimum capacity of the array. |
This function increases the capacity of the array to at least n elements. The current values of the array elements are preserved.
void blaze::SmallArray< T, N, A >::resize | ( | size_t | n | ) |
Changing the size of the array.
n | The new size of the array. |
This function resizes the array using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the array is too small. New array elements are not initialized!
void blaze::SmallArray< T, N, A >::resize | ( | size_t | n, |
const T & | value | ||
) |
Changing the size of the array.
n | The new size of the array. |
value | The initial value of new array elements. |
This function resizes the array using the given size to n. During this operation, new dynamic memory may be allocated in case the capacity of the array is too small. New array elements are initialized to value!
void blaze::SmallArray< T, N, A >::shrinkToFit |
Requesting the removal of unused capacity.
This function minimizes the capacity of the array 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 array are invalidated.
|
inlinenoexcept |
Returns the current size/dimension of the small array.
|
noexcept |
Swapping the contents of two small arrays.
sa | The small array to be swapped. |
This function swaps the contents of two small arrays. 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.