modm API documentation
|
Dynamic Arrays. More...
#include <modm/container/dynamic_array.hpp>
Public Typedefs | |
using | SizeType = std::size_t |
using | const_iterator = std::vector< T, Allocator >::const_iterator |
using | iterator = std::vector< T, Allocator >::iterator |
Public Member Functions | |
DynamicArray (const Allocator &allocator=Allocator ()) | |
Default constructor. More... | |
DynamicArray (SizeType n, const Allocator &allocator=Allocator ()) | |
Allocation constructor. More... | |
DynamicArray (SizeType n, const T &value, const Allocator &allocator=Allocator ()) | |
Repetitive sequence constructor. More... | |
DynamicArray (std::initializer_list< T > init, const Allocator &allocator=Allocator ()) | |
Initializer List constructor. More... | |
bool | isEmpty () const |
Test whether dynamic array is empty. More... | |
SizeType | getSize () const |
Return size. More... | |
SizeType | getCapacity () const |
Return size of allocated storage. More... | |
void | reserve (SizeType n) |
Request a change in capacity. More... | |
void | clear () |
Remove all elements and set capacity to zero. More... | |
void | removeAll () |
Remove all elements. More... | |
T & | operator[] (SizeType index) |
Access element. More... | |
const T & | operator[] (SizeType index) const |
Access element. More... | |
void | append (const T &value) |
Add element at the end. More... | |
void | removeBack () |
Delete last element. More... | |
const T & | getFront () const |
T & | getFront () |
const T & | getBack () const |
T & | getBack () |
iterator | begin () |
const_iterator | begin () const |
iterator | end () |
const_iterator | end () const |
iterator | find (const T &value) |
const_iterator | find (const T &value) const |
Dynamic Arrays.
Dynamic Arrays are a kind of sequence containers. As such, their elements are ordered following a strict linear sequence.
Just as regular arrays, dynamic arrays containers have their elements stored in contiguous storage locations, which means that their elements can be accessed not only using iterators but also using offsets on regular pointers to elements.
Reallocations may be a costly operation in terms of performance, since they generally involve the entire storage space used by the dynamic array to be copied to a new location. Therefore, whenever large increases in size are planned for a dynamic array, it is recommended to explicitly indicate a capacity for the dynamic array using member function DynamicArray::reserve().
|
inline |
Default constructor.
Constructs an empty dynamic array, with no content and a size of zero.
|
inline |
Allocation constructor.
Construct a dynamic array of given capacity. The array will still be empty.
|
inline |
Repetitive sequence constructor.
Construct a dynamic array of given size.
Initializes the dynamic array with its content set to a repetition, n times, of copies of value.
|
inline |
Initializer List constructor.
Construct a dynamic array that holds the values specified in the initialize list
|
inline |
Add element at the end.
Adds a new element at the end of the dynamic array, after its current last element. The content of this new element is initialized to a copy of value
.
This effectively increases the dynamic array size by one, which causes a reallocation of the internal allocated storage if the dynamic array size was equal to the dynamic array capacity before the call. Reallocations invalidate all previously obtained iterators, references and pointers.
|
inline |
Returns a read/write iterator that points to the first element in the list. Iteration is done in ordinary element order.
|
inline |
Returns a read-only (constant) iterator that points to the first element in the list. Iteration is done in ordinary element order.
|
inline |
Remove all elements and set capacity to zero.
Frees all allocated memory and sets the capacity of the container to zero.
|
inline |
Returns a read/write iterator that points one past the last element in the list. Iteration is done in ordinary element order.
|
inline |
Returns a read-only (constant) iterator that points one past the last element in the list. Iteration is done in ordinary element order.
|
inline |
Returns a read/write iterator that points to the first element that contains value. If value is not found, it points to the last element.
|
inline |
Returns a read-only (constant) iterator that points to the first element that contains value. If value is not found, it points to the last element.
|
inline |
Return size of allocated storage.
Returns the size of the allocated storage space in the dynamic array object.
Notice that, in dynamic arrays, the capacity is not necessarily equal to the number of elements that conform the underlying dynamic array content (this can be obtained with member DynamicArray::getSize()), but the capacity of the actual allocated space, which is either equal or greater than the content size.
|
inline |
Return size.
Returns the number of elements in the container.
|
inline |
Test whether dynamic array is empty.
Returns whether the dynamic array container is empty, i.e. whether its size is 0.
|
inline |
Access element.
Returns a reference to the element at position n in the dynamic array container.
|
inline |
Access element.
Returns a reference to the element at position n in the dynamic array container.
|
inline |
Remove all elements.
Keeps the capacity at its current level.
|
inline |
Delete last element.
Removes the last element in the dynamic array, effectively reducing the dynamic array size by one and invalidating all iterators and references to it.
This calls the removed element's destructor.
|
inline |
Request a change in capacity.
Requests that the capacity of the allocated storage space for the elements of the dynamic array container be at least enough to hold n more elements.
This informs the dynamic array of a planned increase in size, although notice that the parameter n informs of a minimum, so the resulting capacity may be any capacity equal or larger than this.