Control Surface master
MIDI Control Surface library for Arduino
Classes | 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 AH::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 168 of file Array.hpp.

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

Classes

class  Iterator
 

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 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 169 of file Array.hpp.

◆ ElementPtrType

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

Definition at line 171 of file Array.hpp.

Constructor & Destructor Documentation

◆ ArraySlice()

ArraySlice ( ElementPtrType  array)
inline

Constructor.

Definition at line 176 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 179 of file Array.hpp.

◆ asArray()

Array< T, N > asArray ( ) const
inline

Definition at line 181 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 273 of file Array.hpp.

◆ begin()

Iterator begin ( ) const
inline

Definition at line 284 of file Array.hpp.

◆ end()

Iterator end ( ) const
inline

Definition at line 291 of file Array.hpp.

Member Data Documentation

◆ array

ElementPtrType array
private

Definition at line 303 of file Array.hpp.


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