SPH
|
Array with fixed number of allocated elements. More...
#include <StaticArray.h>
Public Member Functions | |
StaticArray () | |
Default constructor, calls default constructor on all elements. More... | |
StaticArray (const EmptyArray &) | |
Initialize an empty array. More... | |
StaticArray (std::initializer_list< StorageType > list) | |
Initialize using initializer_list. More... | |
StaticArray (const StaticArray &other)=delete | |
StaticArray (StaticArray &&other) | |
~StaticArray () | |
Destructor, destroys all constructed elements in the array. More... | |
StaticArray & | operator= (const StaticArray &other)=delete |
template<typename U , typename = std::enable_if_t<std::is_default_constructible<T>::value, U>> | |
StaticArray & | operator= (StaticArray< U, N > &&other) |
Move operator for arrays holding default-constructible types. More... | |
template<typename U , int M, typename = std::enable_if_t<std::is_lvalue_reference<T>::value, U>> | |
StaticArray & | operator= (StaticArray< U, M > &&other) |
Special assignment operator for array of references on left-hand side. More... | |
StaticArray | clone () const |
Clones the array, calling copy constructor on all elements. More... | |
void | fill (const T &value) |
Assigns a value to all constructed elements of the array. More... | |
INLINE T & | operator[] (const TCounter idx) noexcept |
Returns the element with given index. More... | |
INLINE const T & | operator[] (const TCounter idx) const noexcept |
Returns the element with given index. More... | |
constexpr INLINE TCounter | maxSize () const noexcept |
Returns the maximum allowed size of the array. More... | |
INLINE TCounter | size () const |
Returns the current size of the array (number of constructed elements). More... | |
INLINE bool | empty () const |
Return true if the array is empty. More... | |
template<typename U , typename = std::enable_if_t<std::is_constructible<StorageType, U>::value>> | |
INLINE void | push (U &&value) |
Inserts a value to the end of the array using copy/move constructor. More... | |
INLINE T | pop () |
Removes and destroys element from the end of the array. More... | |
void | resize (const TCounter newSize) |
Changes size of the array. More... | |
INLINE Iterator< StorageType > | begin () |
INLINE Iterator< const StorageType > | begin () const |
INLINE Iterator< const StorageType > | cbegin () const |
INLINE Iterator< StorageType > | end () |
INLINE Iterator< const StorageType > | end () const |
INLINE Iterator< const StorageType > | cend () const |
operator ArrayView< T > () | |
operator ArrayView< const T > () const | |
bool | operator== (const StaticArray &other) const |
bool | operator!= (const StaticArray &other) const |
Friends | |
template<typename TStream > | |
TStream & | operator<< (TStream &stream, const StaticArray &array) |
Prints content of array to stream. More... | |
Array with fixed number of allocated elements.
Number of actually created elements can be different and it can also be changed; elements can be created and destroyed, although it is not possible to construct more elements than the maximum allocated number, determined by template parameter N or function maxSize. The array is intentionally non-copyable to avoid accidentaly copying values, where move or pass-by-reference is possible.
Definition at line 19 of file StaticArray.h.
|
inline |
Default constructor, calls default constructor on all elements.
Definition at line 28 of file StaticArray.h.
|
inline |
Initialize an empty array.
This effectively creates an empty stack; all N elements are allocated, but none is constructed and size of the array is zero.
Definition at line 41 of file StaticArray.h.
|
inline |
Initialize using initializer_list.
The size of the list must be smaller or equal to N. All N elements are all allocated, elements are constructed from initializer_list using copy constructor.
Definition at line 49 of file StaticArray.h.
|
delete |
|
inline |
Definition at line 59 of file StaticArray.h.
|
inline |
Destructor, destroys all constructed elements in the array.
Definition at line 68 of file StaticArray.h.
|
inline |
Definition at line 198 of file StaticArray.h.
|
inline |
Definition at line 202 of file StaticArray.h.
|
inline |
Definition at line 206 of file StaticArray.h.
|
inline |
Definition at line 218 of file StaticArray.h.
|
inline |
Clones the array, calling copy constructor on all elements.
The size of the cloned array corresponds to current size of this array.
Definition at line 110 of file StaticArray.h.
|
inline |
Return true if the array is empty.
Depends only on number of constructed elements, not allocated size.
Definition at line 154 of file StaticArray.h.
|
inline |
Definition at line 210 of file StaticArray.h.
|
inline |
Definition at line 214 of file StaticArray.h.
|
inline |
Assigns a value to all constructed elements of the array.
Does not resize the array.
Definition at line 121 of file StaticArray.h.
|
inlineconstexprnoexcept |
Returns the maximum allowed size of the array.
Definition at line 140 of file StaticArray.h.
|
inline |
Definition at line 226 of file StaticArray.h.
|
inline |
Definition at line 222 of file StaticArray.h.
|
inline |
Definition at line 242 of file StaticArray.h.
|
delete |
|
inline |
Special assignment operator for array of references on left-hand side.
Can be used similarly to std::tie; a function may return multiple values by wrapping them into StaticArray<T>, these values can be then saved individual variables by wrapping the variables into StaticArray<T&>. A big advantage over tuple is the option to return a variable number of elements (i.e. number of arguments is not known at compile time).
Definition at line 99 of file StaticArray.h.
|
inline |
Move operator for arrays holding default-constructible types.
Resizes array and moves all elements of the rhs array.
Definition at line 83 of file StaticArray.h.
|
inline |
Definition at line 230 of file StaticArray.h.
|
inlinenoexcept |
Returns the element with given index.
Definition at line 134 of file StaticArray.h.
|
inlinenoexcept |
Returns the element with given index.
Definition at line 128 of file StaticArray.h.
|
inline |
Removes and destroys element from the end of the array.
The removed element is returned from the function. Array must not be empty, checked by assert.
Definition at line 170 of file StaticArray.h.
|
inline |
Inserts a value to the end of the array using copy/move constructor.
The current size of the array must be less than N, checked by assert.
Definition at line 162 of file StaticArray.h.
|
inline |
Changes size of the array.
New size must be between 0 and N. If the array is shrinked, elements from the end of the array are destroyed; if the array is enlarged, new elements are created using default constructor.
Definition at line 182 of file StaticArray.h.
|
inline |
Returns the current size of the array (number of constructed elements).
Can be between 0 and N.
Definition at line 147 of file StaticArray.h.
|
friend |
Prints content of array to stream.
Stored values must have overloaded << operator.
Definition at line 250 of file StaticArray.h.