Arduino Helpers master
Utility library for Arduino
Public Types | Public Member Functions | Private Types | Private Attributes | Related Functions | List of all members
ArraySlice< T, N, Reverse, Const > Class Template Reference

#include <AH/Containers/Array.hpp>

Detailed Description

template<class T, size_t N, bool Reverse = false, bool Const = true>
class ArraySlice< T, N, Reverse, Const >

Class for a view on a slice of an array.

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

Template Parameters
TThe type of elements of the Array.
NThe size of the slice.
ReverseWhether the slice is reversed or not.
ConstWhether to save a read-only or mutable reference to the Array.

Definition at line 164 of file Array.hpp.

+ Collaboration diagram for ArraySlice< T, N, Reverse, Const >:

Public Types

using iterator = typename std::conditional< Reverse, std::reverse_iterator< ElementPtrType >, ElementPtrType >::type
 

Public Member Functions

 ArraySlice (ElementPtrType array)
 Constructor. More...
 
 operator Array< T, N > () const
 Implicit conversion from slice to new array (creates a copy). More...
 
Array< T, N > asArray () const
 
ElementRefType operator[] (size_t index) const
 Get the element at the given index. More...
 
iterator begin () const
 
iterator end () const
 
template<size_t Start, size_t End>
ArraySlice< T, abs_diff(End, Start)+1, Reverse ^(End< Start), Const > slice () const
 

Private Types

using ElementRefType = typename std::conditional< Const, const T &, T & >::type
 
using ElementPtrType = typename std::conditional< Const, const T *, T * >::type
 

Private Attributes

ElementPtrType array
 

Related Functions

(Note that these are not member functions.)

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, 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, 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, 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, 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 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 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, 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, 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 T , size_t N, bool Reverse, bool Const>
Array< decltype(-T {}), N > operator- (ArraySlice< T, N, Reverse, Const > a)
 -Slice More...
 

Member Typedef Documentation

◆ ElementRefType

using ElementRefType = typename std::conditional<Const, const T &, T &>::type
private

Definition at line 165 of file Array.hpp.

◆ ElementPtrType

using ElementPtrType = typename std::conditional<Const, const T *, T *>::type
private

Definition at line 167 of file Array.hpp.

◆ iterator

using iterator = typename std::conditional< Reverse, std::reverse_iterator<ElementPtrType>, ElementPtrType>::type

Definition at line 184 of file Array.hpp.

Constructor & Destructor Documentation

◆ ArraySlice()

ArraySlice ( ElementPtrType  array)
inline

Constructor.

Definition at line 172 of file Array.hpp.

Member Function Documentation

◆ operator Array< T, N >()

operator Array< T, N > ( ) const
inline

Implicit conversion from slice to new array (creates a copy).

Definition at line 175 of file Array.hpp.

◆ asArray()

Array< T, N > asArray ( ) const
inline

Definition at line 177 of file Array.hpp.

◆ operator[]()

ElementRefType operator[] ( size_t  index) const
inline

Get the element at the given index.

Note
Bounds checking is performed. If fatal errors are disabled, the last element is returned if the index is out of bounds.
Parameters
indexThe (zero-based) index of the element to return.

Definition at line 196 of file Array.hpp.

◆ begin()

iterator begin ( ) const
inline

Definition at line 207 of file Array.hpp.

◆ end()

iterator end ( ) const
inline

Definition at line 214 of file Array.hpp.

Member Data Documentation

◆ array

ElementPtrType array
private

Definition at line 226 of file Array.hpp.


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