Sane C++ Libraries
C++ Platform Abstraction Libraries
Loading...
Searching...
No Matches
SC::Array< T, N > Struct Template Reference

A contiguous sequence of elements kept inside its inline storage. More...

#include <Array.h>

Inheritance diagram for SC::Array< T, N >:
SC::Segment< detail::ArrayVTable< T, N > >

Public Types

using Parent = Segment<detail::ArrayVTable<T, N>>
 

Public Member Functions

 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)
 
template<typename U >
bool contains (const U &value, size_t *index=nullptr) const
 Check if the current array contains a given value.
 
template<typename Lambda >
bool find (Lambda &&lambda, size_t *index=nullptr) const
 Finds the first item in array matching criteria given by the lambda.
 
template<typename Lambda >
bool removeAll (Lambda &&criteria)
 Removes all items matching criteria given by Lambda.
 
template<typename U >
bool remove (const U &value)
 Removes all values equal to value
 

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).

Array<int, 3> myVector;
SC_TRY(myVector.push_back(1));
SC_TRY(myVector.push_back(2));
SC_TRY(myVector.push_back(3));
(void)myVector.push_back(4); // <-- This will fail
SC_TRY(myVector.pop_back());
SC_TRY(myVector.pop_front());
SC_TRY(myVector.pop_front());
(void)myVector.pop_front(); // <-- This will fail
console.print("Array<int, 3> is {}", myVector.isEmpty() ? "empty" : "not empty");

Member Function Documentation

◆ contains()

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

Check if the current array contains a given value.

Template Parameters
UType of the object being searched
Parameters
valueValue being searched
indexif passed in != nullptr, receives index where item was found. Only written if function returns true
Returns
true if the array contains the given value.

◆ find()

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

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.

◆ remove()

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

Removes all values equal to value

Template Parameters
UType of the Value
Parameters
valueValue to be removed
Returns
true if at least one item has been removed

◆ removeAll()

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

Removes all items matching criteria given by Lambda.

Template Parameters
LambdaType of the functor/lambda with a bool operator()(const T&) operator
Parameters
criteriaThe lambda/functor passed in
Returns
true if at least one item has been removed

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