FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
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. More...
 
using TREF = T_ &
 The reference type to T. More...
 
using CTREF = const T_ &
 The const reference type to T. More...
 
using TPTR = T_ *
 The pointer type to T. More...
 
using CTPTR = const T_ *
 The const pointer type to T. More...
 

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. More...
 
 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. More...
 
array< T, N > & operator= (const T buffer[N])
 Overwrite every element of this array with every element of buffer. More...
 
array< T, N > & operator= (std::initializer_list< T > list)
 Overwrite every element of this array with every element of list. More...
 
arrayoperator= (const array &that)
 Overwrite every element of this array with every element of that. More...
 
CTPTR data () const
 Get a const pointer to the first element of this array. More...
 
TPTR data ()
 Get a pointer to the first element of this array. More...
 
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. More...
 
TPTR end ()
 Return an iterator to the last element of this array. More...
 
CTPTR begin () const
 Return a const iterator to the first element of this array. More...
 
CTPTR end () const
 Return a const iterator to the last element of this array. More...
 
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. More...
 
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. More...
 

Static Public Attributes

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

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.

Member Typedef Documentation

◆ T

template<typename T_ , uint8_t N_>
using containers::array< T_, N_ >::T = T_

The type of elements held by this array.

Definition at line 38 of file array.h.

◆ TREF

template<typename T_ , uint8_t N_>
using containers::array< T_, N_ >::TREF = T_&

The reference type to T.

Definition at line 42 of file array.h.

◆ CTREF

template<typename T_ , uint8_t N_>
using containers::array< T_, N_ >::CTREF = const T_&

The const reference type to T.

Definition at line 44 of file array.h.

◆ TPTR

template<typename T_ , uint8_t N_>
using containers::array< T_, N_ >::TPTR = T_*

The pointer type to T.

Definition at line 46 of file array.h.

◆ CTPTR

template<typename T_ , uint8_t N_>
using containers::array< T_, N_ >::CTPTR = const T_*

The const pointer type to T.

Definition at line 48 of file array.h.

Constructor & Destructor Documentation

◆ array() [1/3]

template<typename T_ , uint8_t N_>
containers::array< T_, N_ >::array ( T  buffer[N])
inline

Convert a C-style array to an array.

Definition at line 58 of file array.h.

◆ array() [2/3]

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.

◆ array() [3/3]

template<typename T_ , uint8_t N_>
containers::array< T_, N_ >::array ( const array< T, N > &  that)
inline

Copy that array.

Definition at line 87 of file array.h.

Member Function Documentation

◆ operator=() [1/3]

template<typename T_ , uint8_t N_>
array< T, N > & containers::array< T_, N_ >::operator= ( const T  buffer[N])
inline

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

Definition at line 98 of file array.h.

◆ operator=() [2/3]

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.

◆ operator=() [3/3]

template<typename T_ , uint8_t N_>
array & containers::array< T_, N_ >::operator= ( const array< T_, N_ > &  that)
inline

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

Definition at line 128 of file array.h.

◆ data() [1/2]

template<typename T_ , uint8_t N_>
CTPTR containers::array< T_, N_ >::data ( ) const
inline

Get a const pointer to the first element of this array.

Definition at line 141 of file array.h.

◆ data() [2/2]

template<typename T_ , uint8_t N_>
TPTR containers::array< T_, N_ >::data ( )
inline

Get a pointer to the first element of this array.

Definition at line 149 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 158 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 170 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 182 of file array.h.

◆ begin() [1/2]

template<typename T_ , uint8_t N_>
TPTR containers::array< T_, N_ >::begin ( )
inline

Return an iterator to the first element of this array.

Definition at line 188 of file array.h.

◆ end() [1/2]

template<typename T_ , uint8_t N_>
TPTR containers::array< T_, N_ >::end ( )
inline

Return an iterator to the last element of this array.

Definition at line 194 of file array.h.

◆ begin() [2/2]

template<typename T_ , uint8_t N_>
CTPTR containers::array< T_, N_ >::begin ( ) const
inline

Return a const iterator to the first element of this array.

Definition at line 200 of file array.h.

◆ end() [2/2]

template<typename T_ , uint8_t N_>
CTPTR containers::array< T_, N_ >::end ( ) const
inline

Return a const iterator to the last element of this array.

Definition at line 206 of file array.h.

◆ set() [1/2]

template<typename T_ , uint8_t N_>
template<uint8_t NN>
void containers::array< T_, N_ >::set ( uint8_t  index,
const T(&)  buffer[NN] 
)
inline

Replace NN elements of this array, starting at index element, with elements from buffer.

Definition at line 216 of file array.h.

◆ set() [2/2]

template<typename T_ , uint8_t N_>
template<uint8_t NN>
void containers::array< T_, N_ >::set ( uint8_t  index,
const array< T, NN > &  buffer 
)
inline

Replace NN elements of this array, starting at index element, with elements from buffer.

Definition at line 231 of file array.h.

Member Data Documentation

◆ N

template<typename T_ , uint8_t N_>
constexpr uint8_t containers::array< T_, N_ >::N = N_
staticconstexpr

The number of elements in this array.

Definition at line 40 of file array.h.


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