#include <flexible_array.h>
FlexibleArray can be used instead of e.g. BaseArray when you don't need dynamic reallocation but make sure in advance to provide enough memory. The class itself uses no allocation, the memory for the count and all elements is within the class itself. This leads to better performance due to improved cache locality.
There are two typical use cases:
T | Type of the array elements. |
COUNT | The class to use for the count member. Int by default. |
Public Types | |
using | ValueType = T |
using | Iterator = BaseIterator< FlexibleArray, false > |
using | ConstIterator = BaseIterator< const FlexibleArray, false > |
Static Public Member Functions | |
template<typename C = FlexibleArray> | |
static Int | GetSize (Int cnt) |
static ResultPtr< FlexibleArray > | Create (Int cnt) |
static ResultPtr< FlexibleArray > | Create (Int cnt, Int capacity) |
static ResultPtr< FlexibleArray > | Create (const Block< const T > &values) |
static ResultPtr< FlexibleArray > | Create (const MoveBlock< T > &values) |
static MAXON_ATTRIBUTE_FORCE_INLINE const FlexibleArray & | NullValue () |
Private Attributes | |
COUNT | _count |
T | _elements [] |
using ValueType = T |
The element type.
using Iterator = BaseIterator<FlexibleArray, false> |
using ConstIterator = BaseIterator<const FlexibleArray, false> |
|
explicit |
Constructs a FlexibleArray with cnt elements. All elements will be default-initialized. The storage memory used for the constructor call needs to be large enough to hold those elements.
[in] | cnt | Number of elements. |
|
explicit |
Constructs a FlexibleArray with a copy of src. All elements will be copied from src. The storage memory used for the constructor call needs to be large enough to hold those elements.
[in] | src | A block of elements to copy. |
|
explicit |
Constructs a FlexibleArray from src. All elements will be moved from src. The storage memory used for the constructor call needs to be large enough to hold those elements.
[in] | src | A block of elements to move. |
FlexibleArray | ( | Int | cnt, |
ENUM_DONT_INITIALIZE | |||
) |
Constructs a FlexibleArray with cnt elements, but without any initialization of the elements. The storage memory used for the constructor call needs to be large enough to hold those elements.
[in] | cnt | Number of elements. |
~FlexibleArray | ( | ) |
MAXON_DISALLOW_COPY_AND_ASSIGN | ( | FlexibleArray< T, COUNT > | ) |
Block<const T> ToBlock | ( | ) | const |
Returns a Block<const T> which represents the elements of the array.
Block<T> ToBlock | ( | ) |
Returns a Block<T> which represents the elements of the array.
operator Block< const T > | ( | ) | const |
Converts this FlexibleArray to a Block<const T> which represents the elements of the array.
operator Block< T > | ( | ) |
Converts this FlexibleArray to a Block<T> which represents the elements of the array.
Returns a sub block of this array with contains the elements from the given start
index up to but not including the given end
index.
[in] | start | Start index of the sub block. |
[in] | end | End index of the sub block. The end index is exclusive. |
start
up to end
. Returns a sub block of this array with contains the elements from the given start
index up to but not including the given end
index.
[in] | start | Start index of the sub block. |
[in] | end | End index of the sub block. The end index is exclusive. |
start
up to end
. Returns a sub block of this array with contains the elements from the given start
index up to the end of the block.
[in] | start | Start index of the sub block. |
start
. Returns a sub block of this array with contains the elements from the given start
index up to the end of the block.
[in] | start | Start index of the sub block. |
start
. Int GetCount | ( | ) | const |
Gets the number of array elements.
Bool IsEmpty | ( | ) | const |
Checks if the array is empty. This is the same as {GetCount() == 0}.
Bool IsPopulated | ( | ) | const |
Checks if the array is populated. This is the same as {GetCount() != 0}.
void Shrink | ( | Int | cnt | ) |
Shrinks this array by cnt elements. These are removed (and destructed) from the end.
[in] | cnt | Number of elements to remove. |
void Erase | ( | Int | index | ) |
Erases the element at index. Elements behind index are moved by one.
[in] | index | Index of the element to remove. |
Computes the required size for an allocation of class C when C has FlexibleArray as last member and cnt element shall be held in the array.
C | Class with a FlexibleArray as last member. |
[in] | cnt | Number of elements to be held in the FlexibleArray. |
|
static |
Creates a FlexibleArray of the given size in dynamic memory. The elements are default-initialized.
[in] | cnt | Number of elements to be held in the FlexibleArray. |
|
static |
Creates a FlexibleArray of the given size in dynamic memory. The elements are default-initialized.
[in] | cnt | Initial number of elements in the FlexibleArray. |
[in] | capacity | Maximum number of elements to be held in the FlexibleArray. |
|
static |
Creates a FlexibleArray of the given content in dynamic memory. All elements are copied from the values block.
[in] | values | A block of initial values for the elements of the FlexibleArray. |
|
static |
Creates a FlexibleArray of the given content in dynamic memory. All elements are moved from the values block.
[in] | values | A block of initial values for the elements of the FlexibleArray. |
T& operator[] | ( | Int | index | ) |
Returns the element at the given index
of this array.
[in] | index | Index into the array. |
index
. const T& operator[] | ( | Int | index | ) | const |
Returns the element at the given index
of this array.
[in] | index | Index into the array. |
index
. const T* GetFirst | ( | ) | const |
Returns the first element of this array. Even for an empty array this will return a non-null pointer.
T* GetFirst | ( | ) |
Returns the first element of this array. Even for an empty array this will return a non-null pointer.
const T* GetLast | ( | ) | const |
Returns the last element of this array. For an empty array this will return nullptr.
T* GetLast | ( | ) |
Returns the last element of this array. For an empty array this will return nullptr.
Iterator Begin | ( | ) |
Iterator End | ( | ) |
ConstIterator Begin | ( | ) | const |
ConstIterator End | ( | ) | const |
Bool operator== | ( | const FlexibleArray< T, COUNT > & | other | ) | const |
Bool operator!= | ( | const FlexibleArray< T, COUNT > & | other | ) | const |
HashInt GetHashCode | ( | ) | const |
Returns the hash code of this @CLASS.
String ToString | ( | const FormatStatement * | fs = nullptr | ) | const |
|
static |
const COUNT& PrivateGetCount | ( | ) | const |
COUNT& PrivateGetCount | ( | ) |
|
private |
|
private |