FastArduino  v1.8
C++ library to build fast but small Arduino/AVR projects
containers::array< T_, N_ > Class Template Reference

Container that encapsulates a fixed size array. More...

#include <fastarduino/array.h>

Public Types

using T = T_
 The type of elements held by this array.
 
using TREF = T_ &
 The reference type to T.
 
using CTREF = const T_ &
 The const reference type to T.
 
using TPTR = T_ *
 The pointer type to T.
 
using CTPTR = const T_ *
 The const pointer type to T.
 

Public Member Functions

 array ()=default
 Create a default array of N elements of type T.
 
 array (T buffer[N])
 Convert a C-style array to an array.
 
 array (std::initializer_list< T > list)
 Create an array from a braced-list of elements. More...
 
 array (const array< T, N > &that)
 Copy that array.
 
array< T, N > & operator= (const T buffer[N])
 Overwrite every element of this array with every element of buffer.
 
array< T, N > & operator= (std::initializer_list< T > list)
 Overwrite every element of this array with every element of list. More...
 
array< T, N > & operator= (const array< T, N > &that)
 Overwrite every element of this array with every element of that.
 
CTPTR data () const
 Get a const pointer to the first element of this array.
 
TPTR data ()
 Get a pointer to the first element of this array.
 
constexpr uint8_t size () const
 Get the number of elements in this array. More...
 
CTREF operator[] (uint8_t index) const
 Get a const reference to the element at index in this array. More...
 
TREF operator[] (uint8_t index)
 Get a reference to the element at index in this array. More...
 
TPTR begin ()
 Return an iterator to the first element of this array.
 
TPTR end ()
 Return an iterator to the last element of this array.
 
CTPTR begin () const
 Return a const iterator to the first element of this array.
 
CTPTR end () const
 Return a const iterator to the last element of this array.
 
template<uint8_t NN>
void set (uint8_t index, const T(&buffer)[NN])
 Replace NN elements of this array, starting at index element, with elements from buffer.
 
template<uint8_t NN>
void set (uint8_t index, const array< T, NN > &buffer)
 Replace NN elements of this array, starting at index element, with elements from buffer.
 

Static Public Attributes

static constexpr uint8_t N = N_
 The number of elements in this array.
 

Detailed Description

template<typename T_, uint8_t N_>
class containers::array< T_, N_ >

Container that encapsulates a fixed size array.

This can be used as would be a C-style array (same operators) without any impact on performance. This also allows, for instance, to use a braced-list as a way to initialiaze or replace the values in this array.

Template Parameters
T_the type of elements in this array
N_the number of elements in this array

Definition at line 34 of file array.h.

Constructor & Destructor Documentation

◆ array()

template<typename T_ , uint8_t N_>
containers::array< T_, N_ >::array ( std::initializer_list< T list)
inline

Create an array from a braced-list of elements.

If list has less than N elements, all remaining elements from this array will be reset to their default.

Definition at line 71 of file array.h.

Member Function Documentation

◆ operator=()

template<typename T_ , uint8_t N_>
array<T, N>& containers::array< T_, N_ >::operator= ( std::initializer_list< T list)
inline

Overwrite every element of this array with every element of list.

If list has less than N elements, all remaining elements from this array will be reset to their default.

Definition at line 112 of file array.h.

◆ size()

template<typename T_ , uint8_t N_>
constexpr uint8_t containers::array< T_, N_ >::size ( ) const
inlineconstexpr

Get the number of elements in this array.

See also
N

Definition at line 157 of file array.h.

◆ operator[]() [1/2]

template<typename T_ , uint8_t N_>
CTREF containers::array< T_, N_ >::operator[] ( uint8_t  index) const
inline

Get a const reference to the element at index in this array.

This can be used as an rvalue.

Warning
There is no control of boundaries, hence the caller must ensure that index is strictly less than N, otherwise behavior is undefined.

Definition at line 169 of file array.h.

◆ operator[]() [2/2]

template<typename T_ , uint8_t N_>
TREF containers::array< T_, N_ >::operator[] ( uint8_t  index)
inline

Get a reference to the element at index in this array.

This can be used as an lvalue.

Warning
There is no control of boundaries, hence the caller must ensure that index is strictly less than N, otherwise behavior is undefined.

Definition at line 181 of file array.h.


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