![]() |
nCine 2025.06.r503-ff15d8d
A cross-platform 2D game engine
|
A dynamic array based on templates that stores elements in the heap. More...
#include <Array.h>
Public Types | |
using | Iterator = ArrayIterator< T, false > |
Iterator type. | |
using | ConstIterator = ArrayIterator< T, true > |
Constant iterator type. | |
using | ReverseIterator = nctl::ReverseIterator< Iterator > |
Reverse iterator type. | |
using | ConstReverseIterator = nctl::ReverseIterator< ConstIterator > |
Reverse constant iterator type. | |
Public Member Functions | |
Array () | |
Constructs an array without allocating memory. | |
Array (unsigned int capacity) | |
Constructs an array with explicit capacity. | |
Array (unsigned int capacity, ArrayMode mode) | |
Constructs an array with explicit capacity and the option for it to be fixed. | |
Array (const Array &other) | |
Copy constructor. | |
Array (Array &&other) | |
Move constructor. | |
Array & | operator= (const Array &other) |
Assignment operator. | |
Array & | operator= (Array &&other) |
Move assignment operator. | |
void | swap (Array &first, Array &second) |
Swaps two arrays without copying their data. | |
Iterator | begin () |
Returns an iterator to the first element. | |
ReverseIterator | rBegin () |
Returns a reverse iterator to the last element. | |
Iterator | end () |
Returns an iterator to past the last element. | |
ReverseIterator | rEnd () |
Returns a reverse iterator to prior the first element. | |
ConstIterator | begin () const |
Returns a constant iterator to the first element. | |
ConstReverseIterator | rBegin () const |
Returns a constant reverse iterator to the last element. | |
ConstIterator | end () const |
Returns a constant iterator to past the last lement. | |
ConstReverseIterator | rEnd () const |
Returns a constant reverse iterator to prior the first element. | |
ConstIterator | cBegin () const |
Returns a constant iterator to the first element. | |
ConstReverseIterator | crBegin () const |
Returns a constant reverse iterator to the last element. | |
ConstIterator | cEnd () const |
Returns a constant iterator to past the last lement. | |
ConstReverseIterator | crEnd () const |
Returns a constant reverse iterator to prior the first element. | |
bool | isEmpty () const |
Returns true if the array is empty. | |
unsigned int | size () const |
Returns the array size. | |
unsigned int | capacity () const |
Returns the array capacity. | |
void | setSize (unsigned int newSize) |
Sets a new size for the array (allowing for "holes") | |
void | setCapacity (unsigned int newCapacity) |
Sets a new capacity for the array (can be bigger or smaller than the current one) | |
void | shrinkToFit () |
Decreases the capacity to match the current size of the array. | |
void | clear () |
Clears the array. | |
const T & | front () const |
Returns a constant reference to the first element in constant time. | |
T & | front () |
Returns a reference to the first element in constant time. | |
const T & | back () const |
Returns a constant reference to the last element in constant time. | |
T & | back () |
Returns a reference to the last element in constant time. | |
void | pushBack (const T &element) |
Appends a new element in constant time, the element is copied into the array. | |
void | pushBack (T &&element) |
Appends a new element in constant time, the element is moved into the array. | |
template<typename... Args> | |
void | emplaceBack (Args &&... args) |
Constructs a new element at the end of the array. | |
void | popBack () |
Removes the last element in constant time. | |
T * | insertRange (unsigned int index, const T *firstPtr, const T *lastPtr) |
Inserts new elements at the specified position from a source range, last not included (shifting elements around) | |
T * | insertAt (unsigned int index, const T &element) |
Inserts a new element at a specified position (shifting elements around) | |
T * | insertAt (unsigned int index, T &&element) |
Move inserts a new element at a specified position (shifting elements around) | |
template<typename... Args> | |
T * | emplaceAt (unsigned int index, Args &&... args) |
Constructs a new element at the position specified by the index. | |
Iterator | insert (Iterator position, const T &value) |
Inserts a new element at the position specified by the iterator (shifting elements around) | |
Iterator | insert (Iterator position, T &&value) |
Move inserts a new element at the position specified by the iterator (shifting elements around) | |
Iterator | insert (Iterator position, Iterator first, Iterator last) |
Inserts new elements from a source at the position specified by the iterator (shifting elements around) | |
template<typename... Args> | |
Iterator | emplace (Iterator position, Args &&... args) |
Constructs a new element at the position specified by the iterator. | |
T * | removeRange (unsigned int firstIndex, unsigned int lastIndex) |
Removes the specified range of elements, last not included (shifting elements around) | |
Iterator | removeAt (unsigned int index) |
Removes an element at a specified position (shifting elements around) | |
Iterator | erase (Iterator position) |
Removes the element pointed by the iterator (shifting elements around) | |
Iterator | erase (Iterator first, const Iterator last) |
Removes the elements in the range, last not included (shifting elements around) | |
T * | unorderedRemoveRange (unsigned int firstIndex, unsigned int lastIndex) |
Removes the specified range of elements, last not included (moving tail elements in place) | |
Iterator | unorderedRemoveAt (unsigned int index) |
Removes an element at a specified position (moving the last element in place) | |
Iterator | unorderedErase (Iterator position) |
Removes the element pointed by the iterator (moving the last element in place) | |
Iterator | unorderedErase (Iterator first, const Iterator last) |
Removes the elements in the range, last not included (moving tail elements in place) | |
const T & | at (unsigned int index) const |
Read-only access to the specified element (with bounds checking) | |
T & | at (unsigned int index) |
Access to the specified element (with bounds checking) | |
const T & | operator[] (unsigned int index) const |
Read-only subscript operator. | |
T & | operator[] (unsigned int index) |
Subscript operator. | |
const T * | data () const |
Returns a constant pointer to the allocated memory. | |
T * | data () |
Returns a pointer to the allocated memory. | |
A dynamic array based on templates that stores elements in the heap.
|
inline |
Returns the array capacity.
The array has memory allocated to store until the Capacity()
-1 element.
void nctl::Array< T >::clear | ( | ) |
Clears the array.
|
inline |
Returns a pointer to the allocated memory.
When adding new elements through a pointer the size field is not updated, like with std::vector
.
|
inline |
Returns the array size.
The array is filled without gaps until the Size()
-1 element.
Array< T >::Iterator nctl::Array< T >::unorderedErase | ( | Iterator | first, |
const Iterator | last | ||
) |
Removes the elements in the range, last not included (moving tail elements in place)
erase()
but it will not preserve the array order Array< T >::Iterator nctl::Array< T >::unorderedErase | ( | Iterator | position | ) |
Removes the element pointed by the iterator (moving the last element in place)
erase()
but it will not preserve the array order T * nctl::Array< T >::unorderedRemoveRange | ( | unsigned int | firstIndex, |
unsigned int | lastIndex | ||
) |
Removes the specified range of elements, last not included (moving tail elements in place)
removeRange()
but it will not preserve the array order