Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::Array< T, N > Struct Template Reference

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)
 
 Array (const Array &other)
 
 Array (Array &&other)
 
Arrayoperator= (const Array &other)
 
Arrayoperator= (Array &&other)
 
template<int M>
 Array (const Array< T, M > &other)
 
template<int M>
 Array (Array< T, M > &&other)
 
template<int M>
Arrayoperator= (const Array< T, M > &other)
 
template<int M>
Arrayoperator= (Array< T, M > &&other)
 
 Array (Span< const T > span)
 
template<typename U >
 Array (Span< const U > span)
 
Span< const T > toSpanConst () const
 Returns content of the array in a span. More...
 
Span< T > toSpan ()
 Returns content of the array in a span. More...
 
bool push_front (const T &value)
 Copies an element in front of the Array, at position 0. More...
 
bool push_back (const T &value)
 Appends an element copying it at the end of the Array. More...
 
bool push_back (T &&value)
 Appends an element moving it at the end of the Array. More...
 
bool pop_back (T *removedValue=nullptr)
 Removes the last element of the array. More...
 
bool pop_front (T *removedValue=nullptr)
 Removes the first element of the array. More...
 
bool reserve (size_t newCapacity)
 Reserves memory for newCapacity elements. 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 to newSize, preserving existing elements without initializing newly added ones. More...
 
void clear ()
 Destroys all elements in the container, making the array empty. More...
 
bool shrink_to_fit ()
 This operation is a no-op on 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...
 
bool appendMove (Array &&other)
 Appends another array moving its contents at the end of array. More...
 
bool assign (Span< const T > data)
 Replaces contents of the array copying elements from the span. More...
 
template<int M>
bool assign (Array< T, M > &&other)
 Replaces contents of the array moving all elements from the other array. More...
 
bool isEmpty () const
 Returns true if the array is empty. More...
 
size_t size () const
 Returns the size of the array. More...
 
size_t capacity () const
 Returns the capacity of the array. More...
 
const T * data () const
 Gets pointer to first element of the array (or nullptr if empty) More...
 
T * data ()
 Gets pointer to first element of the array (or nullptr if empty) More...
 
T * begin () SC_LANGUAGE_LIFETIME_BOUND
 
const T * begin () const SC_LANGUAGE_LIFETIME_BOUND
 
T * end () SC_LANGUAGE_LIFETIME_BOUND
 
const T * end () const SC_LANGUAGE_LIFETIME_BOUND
 
T & back () SC_LANGUAGE_LIFETIME_BOUND
 
T & front () SC_LANGUAGE_LIFETIME_BOUND
 
T & operator[] (size_t idx) SC_LANGUAGE_LIFETIME_BOUND
 
const T & back () const SC_LANGUAGE_LIFETIME_BOUND
 
const T & front () const SC_LANGUAGE_LIFETIME_BOUND
 
const T & operator[] (size_t idx) const SC_LANGUAGE_LIFETIME_BOUND
 
template<typename U >
bool contains (const U &value, size_t *index=nullptr) const
 Return true if array contains value, returning index of found item (if != nullptr) More...
 
template<typename Lambda >
bool find (Lambda &&lambda, size_t *index=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 by Lambda / Functor with a bool operator()(const T&) More...
 
template<typename U >
bool remove (const U &value)
 Removes all values equal to value More...
 
SegmentHeaderunsafeGetHeader ()
 

Detailed Description

template<typename T, int N>
struct SC::Array< T, N >

A contiguous sequence of elements kept inside its inline storage.

Template Parameters
TType of single element of the Array
NNumber 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).

Constructor & Destructor Documentation

◆ Array()

template<typename T , int N>
SC::Array< T, N >::Array ( )
inline

Constructs an empty Array.

Member Function Documentation

◆ append()

template<typename T , int N>
bool SC::Array< T, N >::append ( Span< const T >  data)
inline

Appends a range of items copying them at the end of array.

◆ appendMove()

template<typename T , int N>
bool SC::Array< T, N >::appendMove ( Array< T, N > &&  other)
inline

Appends another array moving its contents at the end of array.

◆ assign() [1/2]

template<typename T , int N>
template<int M>
bool SC::Array< T, N >::assign ( Array< T, M > &&  other)
inline

Replaces contents of the array moving all elements from the other array.

◆ assign() [2/2]

template<typename T , int N>
bool SC::Array< T, N >::assign ( Span< const T >  data)
inline

Replaces contents of the array copying elements from the span.

◆ capacity()

template<typename T , int N>
size_t SC::Array< T, N >::capacity ( ) const
inline

Returns the capacity of the array.

◆ clear()

template<typename T , int N>
void SC::Array< T, N >::clear ( )
inline

Destroys all elements in the container, making the array empty.

◆ contains()

template<typename T , int N>
template<typename U >
bool SC::Array< T, N >::contains ( const U &  value,
size_t index = nullptr 
) const
inline

Return true if array contains value, returning index of found item (if != nullptr)

Returns
true if the array contains the given value, if false index will not be written

◆ data() [1/2]

template<typename T , int N>
T * SC::Array< T, N >::data ( )
inline

Gets pointer to first element of the array (or nullptr if empty)

◆ data() [2/2]

template<typename T , int N>
const T * SC::Array< T, N >::data ( ) const
inline

Gets pointer to first element of the array (or nullptr if empty)

◆ find()

template<typename T , int N>
template<typename Lambda >
bool SC::Array< T, N >::find ( Lambda &&  lambda,
size_t index = nullptr 
) const
inline

Finds the first item in array matching criteria given by the lambda.

Template Parameters
LambdaType of the Lambda passed that declares a bool operator()(const T&) operator
Parameters
lambdaThe functor or lambda called that evaluates to true when item is found
indexif passed in != nullptr, receives index where item was found.
Returns
true if the wanted value with given criteria is found.

◆ insert()

template<typename T , int N>
bool SC::Array< T, N >::insert ( size_t  idx,
Span< const T >  data 
)
inline

Inserts a range of items copying them at given index.

Parameters
idxIndex where to start inserting the range of items
dataData that will be inserted at index idx (by copy)

◆ isEmpty()

template<typename T , int N>
bool SC::Array< T, N >::isEmpty ( ) const
inline

Returns true if the array is empty.

◆ pop_back()

template<typename T , int N>
bool SC::Array< T, N >::pop_back ( T *  removedValue = nullptr)
inline

Removes the last element of the array.

Parameters
removedValueThe removed value will be returned if != nullptr

◆ pop_front()

template<typename T , int N>
bool SC::Array< T, N >::pop_front ( T *  removedValue = nullptr)
inline

Removes the first element of the array.

Parameters
removedValueThe removed value will be returned if != nullptr

◆ push_back() [1/2]

template<typename T , int N>
bool SC::Array< T, N >::push_back ( const T &  value)
inline

Appends an element copying it at the end of the Array.

◆ push_back() [2/2]

template<typename T , int N>
bool SC::Array< T, N >::push_back ( T &&  value)
inline

Appends an element moving it at the end of the Array.

◆ push_front()

template<typename T , int N>
bool SC::Array< T, N >::push_front ( const T &  value)
inline

Copies an element in front of the Array, at position 0.

◆ remove()

template<typename T , int N>
template<typename U >
bool SC::Array< T, N >::remove ( const U &  value)
inline

Removes all values equal to value

◆ removeAll()

template<typename T , int N>
template<typename Lambda >
bool SC::Array< T, N >::removeAll ( Lambda &&  criteria)
inline

Removes all items matching criteria by Lambda / Functor with a bool operator()(const T&)

◆ removeAt()

template<typename T , int N>
bool SC::Array< T, N >::removeAt ( size_t  index)
inline

Removes an item at a given index.

◆ reserve()

template<typename T , int N>
bool SC::Array< T, N >::reserve ( size_t  newCapacity)
inline

Reserves memory for newCapacity elements.

◆ resize()

template<typename T , int N>
bool SC::Array< T, N >::resize ( size_t  newSize,
const T &  value = T() 
)
inline

Resizes this array to newSize, preserving existing elements.

Parameters
newSizeThe wanted new size of the array
valuea default value that will be used for new elements inserted.
Returns
true if resize succeeded

◆ resizeWithoutInitializing()

template<typename T , int N>
bool SC::Array< T, N >::resizeWithoutInitializing ( size_t  newSize)
inline

Resizes to newSize, preserving existing elements without initializing newly added ones.

◆ shrink_to_fit()

template<typename T , int N>
bool SC::Array< T, N >::shrink_to_fit ( )
inline

This operation is a no-op on Array.

◆ size()

template<typename T , int N>
size_t SC::Array< T, N >::size ( ) const
inline

Returns the size of the array.

◆ toSpan()

template<typename T , int N>
Span< T > SC::Array< T, N >::toSpan ( )
inline

Returns content of the array in a span.

◆ toSpanConst()

template<typename T , int N>
Span< const T > SC::Array< T, N >::toSpanConst ( ) const
inline

Returns content of the array in a span.


The documentation for this struct was generated from the following file: