A contiguous sequence of elements kept inside its inline storage. More...
#include <Array.h>
Public Member Functions | |
Array () | |
Constructs an empty Array. More... | |
Array (std::initializer_list< T > list) | |
Constructs a Array from an initializer list. More... | |
~Array () | |
Destroys the Array, releasing allocated memory. More... | |
Array (const Array &other) | |
Copies array into this array. More... | |
Array (Array &&other) | |
Moves array contents into this array. More... | |
Array & | operator= (const Array &other) |
Move assigns another array to this one. More... | |
Array & | operator= (Array &&other) |
Copy assigns another array to this one. More... | |
template<int M> | |
Array (const Array< T, M > &other) | |
template<int M> | |
Array (Array< T, M > &&other) | |
template<int M> | |
Array & | operator= (const Array< T, M > &other) |
template<int M> | |
Array & | operator= (Array< T, M > &&other) |
Span< const T > | toSpanConst () const SC_LANGUAGE_LIFETIME_BOUND |
Returns a Span wrapping the entire of current array. More... | |
Span< T > | toSpan () SC_LANGUAGE_LIFETIME_BOUND |
Returns a Span wrapping the entire of current array. More... | |
T & | operator[] (size_t index) |
Access item at index. More... | |
const T & | operator[] (size_t index) const |
Access item at index. More... | |
bool | push_front (const T &element) |
Copies an element in front of the Array, at position 0. More... | |
bool | push_front (T &&element) |
Moves an element in front of the Array, at position 0. More... | |
bool | push_back (const T &element) |
Appends an element copying it at the end of the Array. More... | |
bool | push_back (T &&element) |
Appends an element moving it at the end of the Array. More... | |
bool | pop_back () |
Removes the last element of the array. More... | |
bool | pop_front () |
Removes the first element of the array. More... | |
T & | front () |
Access the first element of the Array. More... | |
const T & | front () const |
Access the first element of the Array. More... | |
T & | back () |
Access the last element of the Array. More... | |
const T & | back () const |
Access the last element of the Array. More... | |
bool | reserve (size_t newCapacity) |
Reserves memory for newCapacity elements, allocating memory if necessary. More... | |
bool | resize (size_t newSize, const T &value=T()) |
Resizes this array to newSize, preserving existing elements. More... | |
bool | resizeWithoutInitializing (size_t newSize) |
Resizes this array to newSize, preserving existing elements. More... | |
void | clear () |
Removes all elements from container, calling destructor for each of them. More... | |
void | clearWithoutInitializing () |
Sets size() to zero, without calling destructor on elements. More... | |
bool | shrink_to_fit () |
This operation is a no-op on Array. More... | |
bool | isEmpty () const |
Check if the array is empty. More... | |
size_t | size () const |
Gets size of the array. More... | |
size_t | capacity () const |
Gets capacity of the array. More... | |
T * | begin () SC_LANGUAGE_LIFETIME_BOUND |
Gets pointer to first element of the array. More... | |
const T * | begin () const SC_LANGUAGE_LIFETIME_BOUND |
Gets pointer to first element of the array. More... | |
T * | end () SC_LANGUAGE_LIFETIME_BOUND |
Gets pointer to one after last element of the array. More... | |
const T * | end () const SC_LANGUAGE_LIFETIME_BOUND |
Gets pointer to one after last element of the array. More... | |
T * | data () SC_LANGUAGE_LIFETIME_BOUND |
Gets pointer to first element of the array. More... | |
const T * | data () const SC_LANGUAGE_LIFETIME_BOUND |
Gets pointer to first element of the array. More... | |
bool | insert (size_t idx, Span< const T > data) |
Inserts a range of items copying them at given index. More... | |
bool | append (Span< const T > data) |
Appends a range of items copying them at the end of array. More... | |
template<typename U > | |
bool | append (Span< const U > data) |
Appends a range of items copying them at the end of array. More... | |
template<typename U > | |
bool | appendMove (U &&src) |
Appends another array moving its contents at the end of array. More... | |
template<typename U > | |
bool | contains (const U &value, size_t *foundIndex=nullptr) const |
Check if the current array contains a given value. More... | |
template<typename Lambda > | |
bool | find (Lambda &&lambda, size_t *foundIndex=nullptr) const |
Finds the first item in array matching criteria given by the lambda. More... | |
bool | removeAt (size_t index) |
Removes an item at a given index. More... | |
template<typename Lambda > | |
bool | removeAll (Lambda &&criteria) |
Removes all items matching criteria given by Lambda. More... | |
template<typename U > | |
bool | remove (const U &value) |
Removes all values equal to value More... | |
template<int M> | |
SC::Array< T, N > & | operator= (const Array< T, M > &other) |
template<int M> | |
SC::Array< T, N > & | operator= (Array< T, M > &&other) |
Protected Types | |
using | Parent = SegmentItems< T > |
using | Operations = SegmentOperations< ArrayAllocator, T > |
Protected Attributes | |
SegmentItems< T > | segmentHeader |
union { | |
T items [N] | |
}; | |
Friends | |
template<int > | |
struct | SmallString |
template<typename , int > | |
struct | SmallVector |
A contiguous sequence of elements kept inside its inline storage.
T | Type of single element of the Array |
N | Number of elements contained inside this Array inline storage |
SC::Array is like a SC::Vector but it will only allow up to N
elements in the array, using inline storage, without resorting to heap allocation.
Trying to push or insert more than N elements will fail.
Only up to SC::Array::size elements are valid (and N
- size()
are initialized).
Destroys the Array, releasing allocated memory.
Copies array into this array.
other | The array to be copied |
Moves array contents into this array.
other | The array being moved |
Appends a range of items copying them at the end of array.
data | the range of items to copy |
true
if operation succeeded bool SC::Array< T, N >::append | ( | Span< const U > | data | ) |
Appends a range of items copying them at the end of array.
data | the range of items to copy |
true
if operation succeeded Appends another array moving its contents at the end of array.
U | Type of the array to be move appended |
src | The array to be moved at end of array |
true
if operation succeeded T & SC::Array< T, N >::back |
const T & SC::Array< T, N >::back |
|
inline |
Gets pointer to first element of the array.
|
inline |
Gets pointer to first element of the array.
Gets capacity of the array.
Capacity is always >= size.
|
inline |
Removes all elements from container, calling destructor for each of them.
Doesn't deallocate memory (use shrink_to_fit for that)
|
inline |
Sets size() to zero, without calling destructor on elements.
bool SC::Array< T, N >::contains | ( | const U & | value, |
size_t * | foundIndex = nullptr |
||
) | const |
Check if the current array contains a given value.
U | Type of the object being searched |
value | Value being searched |
foundIndex | if passed in != nullptr , receives index where item was found. Only written if function returns true |
true
if the array contains the given value.
|
inline |
Gets pointer to first element of the array.
|
inline |
Gets pointer to first element of the array.
|
inline |
Gets pointer to one after last element of the array.
|
inline |
Gets pointer to one after last element of the array.
bool SC::Array< T, N >::find | ( | Lambda && | lambda, |
size_t * | foundIndex = nullptr |
||
) | const |
Finds the first item in array matching criteria given by the lambda.
Lambda | Type of the Lambda passed that declares a bool operator()(const T&) operator |
lambda | The functor or lambda called that evaluates to true when item is found |
foundIndex | if passed in != nullptr , receives index where item was found. |
true
if the wanted value with given criteria is found. T & SC::Array< T, N >::front |
const T & SC::Array< T, N >::front |
Inserts a range of items copying them at given index.
idx | Index where to start inserting the range of items |
data | the range of items to copy |
true
if operation succeeded
|
inline |
Check if the array is empty.
true
if array is empty. SC::Array< T, N > & SC::Array< T, N >::operator= | ( | Array< T, N > && | other | ) |
Copy assigns another array to this one.
Contents of this array will be freed.
other | The array being copy assigned |
SC::Array< T, N > & SC::Array< T, N >::operator= | ( | const Array< T, N > & | other | ) |
Move assigns another array to this one.
Contents of this array will be freed.
other | The array being move assigned |
Access item at index.
Bounds checked in debug.
index | index of the item to be accessed |
Access item at index.
Bounds checked in debug.
index | index of the item to be accessed |
bool SC::Array< T, N >::pop_back |
Removes the last element of the array.
true
if the operation succeeds bool SC::Array< T, N >::pop_front |
Removes the first element of the array.
true
if the operation succeeds bool SC::Array< T, N >::push_back | ( | const T & | element | ) |
bool SC::Array< T, N >::push_back | ( | T && | element | ) |
|
inline |
|
inline |
bool SC::Array< T, N >::remove | ( | const U & | value | ) |
Removes all values equal to value
U | Type of the Value |
value | Value to be removed |
true
if at least one item has been removed bool SC::Array< T, N >::removeAll | ( | Lambda && | criteria | ) |
Removes all items matching criteria given by Lambda.
Lambda | Type of the functor/lambda with a bool operator()(const T&) operator |
criteria | The lambda/functor passed in |
true
if at least one item has been removed Removes an item at a given index.
index | Index where the item must be removed |
true
if operation succeeded (index is within bounds) Reserves memory for newCapacity elements, allocating memory if necessary.
newCapacity | The wanted new capacity for this Array |
true
if memory reservation succeeded bool SC::Array< T, N >::resize | ( | size_t | newSize, |
const T & | value = T() |
||
) |
Resizes this array to newSize, preserving existing elements.
newSize | The wanted new size of the array |
value | a default value that will be used for new elements inserted. |
true
if resize succeeded Resizes this array to newSize, preserving existing elements.
Does not initialize the items between size() and capacity(). Be careful, it's up to the caller to initialize such items to avoid UB.
newSize | The wanted new size of the array |
true
if resize succeeded
|
inline |
This operation is a no-op on Array.
true
Gets size of the array.