Arduino Helpers master
Utility library for Arduino
Classes | Typedefs | Functions
Containers

Detailed Description

Containers like Array, BitArray, DoublyLinkedList.

Classes

class  ArraySlice< T, N, Reverse, Const >
 Class for a view on a slice of an array. More...
 
struct  Array< T, N >
 An array wrapper for easy copying, comparing, and iterating. More...
 
class  BitArray< N >
 A class for arrays of bits. More...
 
class  DoublyLinkedList< Node >
 A class for doubly linked lists. More...
 
class  DoublyLinkable< Node >
 A class that can be inherited from to allow inserting into a DoublyLinkedList. More...
 

Typedefs

template<class T , size_t NumRows, size_t NumCols>
using Array2D = Array< Array< T, NumCols >, NumRows >
 An easy alias for two-dimensional Arrays. More...
 

Functions

template<class T , size_t N, class G >
Array< T, N > generateArray (G generator)
 Generate an array using the given generator. More...
 
template<size_t N, class G >
auto generateArray (G generator) -> Array< decltype(generator()), N >
 Generate an array using the given generator. More...
 
template<class T , size_t N, class U >
Array< T, N > copyAs (const Array< U, N > &src)
 Copy an Array to an Array of a different type. More...
 
template<class F , class U , size_t N>
Array< decltype(F{}(U{})), N > apply (const Array< U, N > &src, F f)
 Apply a function to all elements of the array and return a copy. More...
 
template<class T , size_t N, class... Args>
Array< T, N > fillArray (Args... args)
 Fill the array with the same value for each element. More...
 
template<class T , size_t N, class U , class V = U>
Array< T, N > generateIncrementalArray (U start=0, V increment=V(1))
 Generate an array where the first value is given, and the subsequent values are calculated as the previous value incremented with a given value:
\( x[0] = \mathrm{start} \)
\( x[k+1] = x[k] + \mathrm{increment} \) . More...
 
template<class T , size_t M, size_t N>
Array< T, M+N > cat (const Array< T, M > &a, const Array< T, N > &b)
 Concatenate two arrays. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Reverse2, bool Const1, bool Const2>
Array< decltype(T1() *T2()), N1+N2 - 1 > distribute (const ArraySlice< T1, N1, Reverse1, Const1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Const1>
Array< decltype(T1() *T2()), N1+N2 - 1 > distribute (const ArraySlice< T1, N1, Reverse1, Const1 > &a, const Array< T2, N2 > &b)
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse2, bool Const2>
Array< decltype(T1() *T2()), N1+N2 - 1 > distribute (const Array< T1, N1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
 
template<class T1 , class T2 , size_t N1, size_t N2>
Array< decltype(T1() *T2()), N1+N2 - 1 > distribute (const Array< T1, N1 > &a, const Array< T2, N2 > &b)
 
template<size_t Start = 0, size_t End = N - 1>
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), false > slice ()
 Get a view on a slice of the Array. More...
 
template<size_t Start = 0, size_t End = N - 1>
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), true > slice () const
 Get a read-only view on a slice of the Array. More...
 
template<size_t Start, size_t End>
ArraySlice< T, abs_diff(End, Start)+1, Reverse ^(End< Start), Const > slice () const
 
template<class T , size_t N, bool Reverse, bool Const>
ArraySlice< T, N, Reverse, Const >::iterator operator+ (typename ArraySlice< T, N, Reverse, Const >::iterator::difference_type n, typename ArraySlice< T, N, Reverse, Const >::iterator a)
 <T, N, Reverse, Const>::iterator More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Reverse2, bool Const1, bool Const2>
bool operator== (ArraySlice< T1, N1, Reverse1, Const1 > a, ArraySlice< T2, N2, Reverse2, Const2 > b)
 Slice == Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse2, bool Const2>
bool operator== (const Array< T1, N1 > &a, ArraySlice< T2, N2, Reverse2, Const2 > b)
 Array == Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Const1>
bool operator== (ArraySlice< T1, N1, Reverse1, Const1 > a, const Array< T2, N2 > &b)
 Slice == Array. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Reverse2, bool Const1, bool Const2>
bool operator!= (ArraySlice< T1, N1, Reverse1, Const1 > a, ArraySlice< T2, N2, Reverse2, Const2 > b)
 Slice != Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse2, bool Const2>
bool operator!= (const Array< T1, N1 > &a, ArraySlice< T2, N2, Reverse2, Const2 > b)
 Array != Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Const1>
bool operator!= (ArraySlice< T1, N1, Reverse1, Const1 > a, const Array< T2, N2 > &b)
 Slice != Array. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Reverse2, bool Const1, bool Const2>
Array< decltype(T1 {}+T2 {}), N1 > operator+ (ArraySlice< T1, N1, Reverse1, Const1 > a, ArraySlice< T2, N2, Reverse2, Const2 > b)
 Slice + Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2>
Array< decltype(T1 {}+T2 {}), N1 > operator+ (const Array< T1, N1 > &a, const Array< T2, N2 > &b)
 Array + Array. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Reverse2, bool Const1, bool Const2>
const ArraySlice< T1, N1, Reverse1, Const1 > & operator+= (const ArraySlice< T1, N1, Reverse1, Const1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
 Slice += Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2>
Array< T1, N1 > & operator+= (Array< T1, N1 > &a, const Array< T2, N2 > &b)
 Array += Array. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Reverse2, bool Const1, bool Const2>
Array< decltype(T1 {} - T2 {}), N1 > operator- (ArraySlice< T1, N1, Reverse1, Const1 > a, ArraySlice< T2, N2, Reverse2, Const2 > b)
 Slice - Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2>
Array< decltype(T1 {} - T2 {}), N1 > operator- (const Array< T1, N1 > &a, const Array< T2, N2 > &b)
 Array - Array. More...
 
template<class T1 , class T2 , size_t N1, size_t N2, bool Reverse1, bool Reverse2, bool Const1, bool Const2>
const ArraySlice< T1, N1, Reverse1, Const1 > & operator-= (const ArraySlice< T1, N1, Reverse1, Const1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
 Slice -= Slice. More...
 
template<class T1 , class T2 , size_t N1, size_t N2>
Array< T1, N1 > & operator-= (Array< T1, N1 > &a, const Array< T2, N2 > &b)
 Array -= Array. More...
 
template<class T1 , class T2 , size_t N1, bool Reverse1, bool Const1>
Array< decltype(T1 {} *T2 {}), N1 > operator* (ArraySlice< T1, N1, Reverse1, Const1 > a, T2 b)
 Slice * Scalar. More...
 
template<class T1 , class T2 , size_t N1>
Array< decltype(T1 {} *T2 {}), N1 > operator* (const Array< T1, N1 > &a, T2 b)
 Array * Scalar. More...
 
template<class T1 , class T2 , size_t N2, bool Reverse2, bool Const2>
Array< decltype(T1 {} *T2 {}), N2 > operator* (T1 a, ArraySlice< T2, N2, Reverse2, Const2 > b)
 Scalar * Slice. More...
 
template<class T1 , class T2 , size_t N2>
Array< decltype(T1 {} *T2 {}), N2 > operator* (T1 a, const Array< T2, N2 > &b)
 Scalar * Array. More...
 
template<class T1 , class T2 , size_t N1, bool Reverse1, bool Const1>
const ArraySlice< T1, N1, Reverse1, Const1 > & operator*= (const ArraySlice< T1, N1, Reverse1, Const1 > &a, T2 b)
 Slice *= Scalar. More...
 
template<class T1 , class T2 , size_t N1>
Array< T1, N1 > & operator*= (Array< T1, N1 > &a, T2 b)
 Array *= Scalar. More...
 
template<class T1 , class T2 , size_t N1, bool Reverse1, bool Const1>
Array< decltype(T1 {}/T2 {}), N1 > operator/ (ArraySlice< T1, N1, Reverse1, Const1 > a, T2 b)
 Slice / Scalar. More...
 
template<class T1 , class T2 , size_t N1>
Array< decltype(T1 {}/T2 {}), N1 > operator/ (const Array< T1, N1 > &a, T2 b)
 Array / Scalar. More...
 
template<class T1 , class T2 , size_t N1, bool Reverse1, bool Const1>
const ArraySlice< T1, N1, Reverse1, Const1 > & operator/= (const ArraySlice< T1, N1, Reverse1, Const1 > &a, T2 b)
 Slice /= Scalar. More...
 
template<class T1 , class T2 , size_t N1>
Array< T1, N1 > & operator/= (Array< T1, N1 > &a, T2 b)
 Array /= Scalar. More...
 
template<class T , size_t N, bool Reverse, bool Const>
Array< decltype(-T {}), N > operator- (ArraySlice< T, N, Reverse, Const > a)
 -Slice More...
 
template<class T , size_t N>
Array< decltype(-T {}), N > operator- (const Array< T, N > &a)
 -Array More...
 

Typedef Documentation

◆ Array2D

using Array2D = Array<Array<T, NumCols>, NumRows>

An easy alias for two-dimensional Arrays.

Definition at line 529 of file Array.hpp.

Function Documentation

◆ generateArray() [1/2]

Array< T, N > generateArray ( generator)

Generate an array using the given generator.

Template Parameters
TThe type of the elements in the array.
NThe number of elements in the array.
GThe generator functor type.
Parameters
generatorA functor that will be called to create each element.
Returns
The generated array.

Definition at line 64 of file ArrayHelpers.hpp.

◆ generateArray() [2/2]

auto generateArray ( generator) -> Array<decltype(generator()), N>

Generate an array using the given generator.

Template Parameters
NThe number of elements in the array.
GThe generator functor type.
Parameters
generatorA functor that will be called to create each element.
Returns
The generated array.

Definition at line 84 of file ArrayHelpers.hpp.

◆ copyAs()

Array< T, N > copyAs ( const Array< U, N > &  src)

Copy an Array to an Array of a different type.

Template Parameters
TThe type of the new array.
NThe number of elements in the arrays.
UThe type of the source array.
Parameters
srcThe source array to be copied.

Definition at line 105 of file ArrayHelpers.hpp.

◆ apply()

Array< decltype(F{}(U{})), N > apply ( const Array< U, N > &  src,
f 
)

Apply a function to all elements of the array and return a copy.

Definition at line 117 of file ArrayHelpers.hpp.

◆ fillArray()

Array< T, N > fillArray ( Args...  args)

Fill the array with the same value for each element.

Definition at line 129 of file ArrayHelpers.hpp.

◆ generateIncrementalArray()

Array< T, N > generateIncrementalArray ( start = 0,
increment = V(1) 
)

Generate an array where the first value is given, and the subsequent values are calculated as the previous value incremented with a given value:
\( x[0] = \mathrm{start} \)
\( x[k+1] = x[k] + \mathrm{increment} \) .

For example:

auto x = generateIncrementalArray<unsigned int, 4>(2, 3);

is equivalent to

Array<unsigned int, 4> x = {2, 5, 8, 11};
An array wrapper for easy copying, comparing, and iterating.
Definition: Array.hpp:32
Template Parameters
TThe type of the elements in the array.
NThe number of elements in the array.
UThe type of the initial value.
VThe type of the value that will be added to each subsequent element.
Parameters
startThe first value in the array.
incrementThe value to add to each subsequent element of the array.
Returns
The generated array.
Examples
Toggle-LEDs.ino.

Definition at line 176 of file ArrayHelpers.hpp.

◆ cat()

Array< T, M+N > cat ( const Array< T, M > &  a,
const Array< T, N > &  b 
)

Concatenate two arrays.

Template Parameters
TThe type of the elements in the array.
MThe number of elements in the first array.
NThe number of elements in the second array.
Parameters
aThe first array.
bThe second array.
Returns
A new array containing the elements of both input arrays (in order).

Definition at line 197 of file ArrayHelpers.hpp.

◆ distribute() [1/4]

Array< decltype(T1() *T2()), N1+N2 - 1 > distribute ( const ArraySlice< T1, N1, Reverse1, Const1 > &  a,
const ArraySlice< T2, N2, Reverse2, Const2 > &  b 
)

Definition at line 211 of file ArrayHelpers.hpp.

◆ distribute() [2/4]

Array< decltype(T1() *T2()), N1+N2 - 1 > distribute ( const ArraySlice< T1, N1, Reverse1, Const1 > &  a,
const Array< T2, N2 > &  b 
)

Definition at line 222 of file ArrayHelpers.hpp.

◆ distribute() [3/4]

Array< decltype(T1() *T2()), N1+N2 - 1 > distribute ( const Array< T1, N1 > &  a,
const ArraySlice< T2, N2, Reverse2, Const2 > &  b 
)

Definition at line 229 of file ArrayHelpers.hpp.

◆ distribute() [4/4]

Array< decltype(T1() *T2()), N1+N2 - 1 > distribute ( const Array< T1, N1 > &  a,
const Array< T2, N2 > &  b 
)

Definition at line 236 of file ArrayHelpers.hpp.

◆ slice() [1/3]

ArraySlice< T, abs_diff(Start, End)+1,(End< Start), false > slice
inline

Get a view on a slice of the Array.

Doesn't copy the contents of the array, it's just a reference to the original array.

Template Parameters
StartThe start index of the slice.
EndThe end index of the slice.

Definition at line 232 of file Array.hpp.

◆ slice() [2/3]

ArraySlice< T, abs_diff(Start, End)+1,(End< Start), true > slice
inline

Get a read-only view on a slice of the Array.

Doesn't copy the contents of the array, it's just a reference to the original array.

Template Parameters
StartThe start index of the slice.
EndThe end index of the slice.

Definition at line 241 of file Array.hpp.

◆ slice() [3/3]

ArraySlice< T, abs_diff(End, Start)+1, Reverse ^(End< Start), Const > slice

Definition at line 250 of file Array.hpp.

◆ operator+() [1/3]

ArraySlice< T, N, Reverse, Const >::iterator operator+ ( typename ArraySlice< T, N, Reverse, Const >::iterator::difference_type  n,
typename ArraySlice< T, N, Reverse, Const >::iterator  a 
)
related

<T, N, Reverse, Const>::iterator

Definition at line 258 of file Array.hpp.

◆ operator==() [1/3]

bool operator== ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
ArraySlice< T2, N2, Reverse2, Const2 >  b 
)
related

Slice == Slice.

Definition at line 270 of file Array.hpp.

◆ operator==() [2/3]

bool operator== ( const Array< T1, N1 > &  a,
ArraySlice< T2, N2, Reverse2, Const2 >  b 
)
related

Array == Slice.

Definition at line 282 of file Array.hpp.

◆ operator==() [3/3]

bool operator== ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
const Array< T2, N2 > &  b 
)
related

Slice == Array.

Definition at line 290 of file Array.hpp.

◆ operator!=() [1/3]

bool operator!= ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
ArraySlice< T2, N2, Reverse2, Const2 >  b 
)
related

Slice != Slice.

Definition at line 301 of file Array.hpp.

◆ operator!=() [2/3]

bool operator!= ( const Array< T1, N1 > &  a,
ArraySlice< T2, N2, Reverse2, Const2 >  b 
)
related

Array != Slice.

Definition at line 309 of file Array.hpp.

◆ operator!=() [3/3]

bool operator!= ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
const Array< T2, N2 > &  b 
)
related

Slice != Array.

Definition at line 317 of file Array.hpp.

◆ operator+() [2/3]

Array< decltype(T1 {}+T2 {}), N1 > operator+ ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
ArraySlice< T2, N2, Reverse2, Const2 >  b 
)
related

Slice + Slice.

Definition at line 329 of file Array.hpp.

◆ operator+() [3/3]

Array< decltype(T1 {}+T2 {}), N1 > operator+ ( const Array< T1, N1 > &  a,
const Array< T2, N2 > &  b 
)
related

Array + Array.

Definition at line 341 of file Array.hpp.

◆ operator+=() [1/2]

const ArraySlice< T1, N1, Reverse1, Const1 > & operator+= ( const ArraySlice< T1, N1, Reverse1, Const1 > &  a,
const ArraySlice< T2, N2, Reverse2, Const2 > &  b 
)
related

Slice += Slice.

Definition at line 351 of file Array.hpp.

◆ operator+=() [2/2]

Array< T1, N1 > & operator+= ( Array< T1, N1 > &  a,
const Array< T2, N2 > &  b 
)
related

Array += Array.

Definition at line 362 of file Array.hpp.

◆ operator-() [1/4]

Array< decltype(T1 {} - T2 {}), N1 > operator- ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
ArraySlice< T2, N2, Reverse2, Const2 >  b 
)
related

Slice - Slice.

Definition at line 374 of file Array.hpp.

◆ operator-() [2/4]

Array< decltype(T1 {} - T2 {}), N1 > operator- ( const Array< T1, N1 > &  a,
const Array< T2, N2 > &  b 
)
related

Array - Array.

Definition at line 386 of file Array.hpp.

◆ operator-=() [1/2]

const ArraySlice< T1, N1, Reverse1, Const1 > & operator-= ( const ArraySlice< T1, N1, Reverse1, Const1 > &  a,
const ArraySlice< T2, N2, Reverse2, Const2 > &  b 
)
related

Slice -= Slice.

Definition at line 396 of file Array.hpp.

◆ operator-=() [2/2]

Array< T1, N1 > & operator-= ( Array< T1, N1 > &  a,
const Array< T2, N2 > &  b 
)
related

Array -= Array.

Definition at line 407 of file Array.hpp.

◆ operator*() [1/4]

Array< decltype(T1 {} *T2 {}), N1 > operator* ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
T2  b 
)
related

Slice * Scalar.

Definition at line 418 of file Array.hpp.

◆ operator*() [2/4]

Array< decltype(T1 {} *T2 {}), N1 > operator* ( const Array< T1, N1 > &  a,
T2  b 
)
related

Array * Scalar.

Definition at line 428 of file Array.hpp.

◆ operator*() [3/4]

Array< decltype(T1 {} *T2 {}), N2 > operator* ( T1  a,
ArraySlice< T2, N2, Reverse2, Const2 >  b 
)
related

Scalar * Slice.

Definition at line 436 of file Array.hpp.

◆ operator*() [4/4]

Array< decltype(T1 {} *T2 {}), N2 > operator* ( T1  a,
const Array< T2, N2 > &  b 
)
related

Scalar * Array.

Definition at line 446 of file Array.hpp.

◆ operator*=() [1/2]

const ArraySlice< T1, N1, Reverse1, Const1 > & operator*= ( const ArraySlice< T1, N1, Reverse1, Const1 > &  a,
T2  b 
)
related

Slice *= Scalar.

Definition at line 454 of file Array.hpp.

◆ operator*=() [2/2]

Array< T1, N1 > & operator*= ( Array< T1, N1 > &  a,
T2  b 
)
related

Array *= Scalar.

Definition at line 463 of file Array.hpp.

◆ operator/() [1/2]

Array< decltype(T1 {}/T2 {}), N1 > operator/ ( ArraySlice< T1, N1, Reverse1, Const1 >  a,
T2  b 
)
related

Slice / Scalar.

Definition at line 474 of file Array.hpp.

◆ operator/() [2/2]

Array< decltype(T1 {}/T2 {}), N1 > operator/ ( const Array< T1, N1 > &  a,
T2  b 
)
related

Array / Scalar.

Definition at line 484 of file Array.hpp.

◆ operator/=() [1/2]

const ArraySlice< T1, N1, Reverse1, Const1 > & operator/= ( const ArraySlice< T1, N1, Reverse1, Const1 > &  a,
T2  b 
)
related

Slice /= Scalar.

Definition at line 492 of file Array.hpp.

◆ operator/=() [2/2]

Array< T1, N1 > & operator/= ( Array< T1, N1 > &  a,
T2  b 
)
related

Array /= Scalar.

Definition at line 501 of file Array.hpp.

◆ operator-() [3/4]

Array< decltype(-T {}), N > operator- ( ArraySlice< T, N, Reverse, Const >  a)
related

-Slice

Definition at line 511 of file Array.hpp.

◆ operator-() [4/4]

Array< decltype(-T {}), N > operator- ( const Array< T, N > &  a)
related

-Array

Definition at line 521 of file Array.hpp.