| 
   
    MIDI Control Surface library for Arduino 
   | 
 
 
 
 
Go to the documentation of this file.
    9 #include <AH/Error/Error.hpp> 
   10 #include <AH/STL/iterator> 
   11 #include <AH/STL/type_traits>  
   18     return a < b ? b - a : a - b;
 
   24 template <
class T, 
size_t N, 
bool Reverse, 
bool Const>
 
   35 template <
class T, 
size_t N>
 
   39     constexpr 
static size_t length = N;
 
   52             ERROR(
F(
"Index out of bounds: ") << index << 
F(
" ≥ ") << N, 0xEDED);
 
   69             ERROR(
F(
"Index out of bounds: ") << index << 
F(
" ≥ ") << N, 0xEDED);
 
   83     const T *
begin()
 const { 
return &data[0]; }
 
   88     T *
end() { 
return &data[N]; }
 
   93     const T *
end()
 const { 
return &data[N]; }
 
  104         for (
size_t i = 0; i < N; i++)
 
  105             if ((*
this)[i] != rhs[i])
 
  130     template <
size_t Start = 0, 
size_t End = N - 1>
 
  137     template <
size_t Start = 0, 
size_t End = N - 1>
 
  144     template <
size_t Start = 0, 
size_t End = N - 1>
 
  148         return This->
slice();
 
  167 template <
class T, 
size_t N, 
bool Reverse = false, 
bool Const = true>
 
  170         typename std::conditional<Const, const T &, T &>::type;
 
  172         typename std::conditional<Const, const T *, T *>::type;
 
  183         for (
size_t i = 0; i < N; ++i)
 
  184             slice[i] = (*
this)[i];
 
  204             Reverse ? --ptr : ++ptr;
 
  209             Reverse ? ++ptr : --ptr;
 
  214             return Reverse ? rhs.
ptr - ptr : ptr - rhs.
ptr;
 
  218             return Reverse ? ptr - rhs : ptr + rhs;
 
  222             return Reverse ? ptr + rhs : ptr - rhs;
 
  226             return Reverse ? rhs.
ptr < ptr : ptr < rhs.
ptr;
 
  230             return Reverse ? rhs.
ptr <= ptr : ptr <= rhs.
ptr;
 
  248             ERROR(
F(
"Index out of bounds: ") << index << 
F(
" ≥ ") << N, 0xEDEF);
 
  252             return array[-index];
 
  271     template <
size_t Start, 
size_t End>
 
  279 template <
class T, 
size_t N>
 
  280 template <
size_t Start, 
size_t End>
 
  283     static_assert(Start < N, 
"");
 
  284     static_assert(End < N, 
"");
 
  285     return &(*this)[Start];
 
  288 template <
class T, 
size_t N>
 
  289 template <
size_t Start, 
size_t End>
 
  290 inline ArraySlice<T, 
abs_diff(Start, End) + 1, (End < Start), true>
 
  291 Array<T, N>::slice()
 const {
 
  292     static_assert(Start < N, 
"");
 
  293     static_assert(End < N, 
"");
 
  294     return &(*this)[Start];
 
  297 template <
class T, 
size_t N, 
bool Reverse, 
bool Const>
 
  298 template <
size_t Start, 
size_t End>
 
  299 ArraySlice<T, 
abs_diff(End, Start) + 1, Reverse ^ (End < Start), Const>
 
  300 ArraySlice<T, N, Reverse, Const>::slice()
 const {
 
  301     static_assert(Start < N, 
"");
 
  302     static_assert(End < N, 
"");
 
  303     return &(*this)[Start];
 
  309 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1,
 
  310           bool Reverse2, 
bool Const1, 
bool Const2>
 
  313     static_assert(N1 == N2, 
"Error: sizes do not match");
 
  314     for (
size_t i = 0; i < N1; ++i)
 
  321 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse2, 
bool Const2>
 
  324     return a.
slice() == b;
 
  328 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1, 
bool Const1>
 
  331     return a == b.
slice();
 
  337 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1,
 
  338           bool Reverse2, 
bool Const1, 
bool Const2>
 
  345 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse2, 
bool Const2>
 
  348     return a.
slice() != b;
 
  352 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1, 
bool Const1>
 
  355     return a != b.
slice();
 
  361 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1,
 
  362           bool Reverse2, 
bool Const1, 
bool Const2>
 
  363 Array<decltype(T1{} + T2{}), N1>
 
  366     static_assert(N1 == N2, 
"Error: sizes do not match");
 
  367     Array<decltype(T1{} + T2{}), N1> result = {{}};
 
  368     for (
size_t i = 0; i < N1; ++i)
 
  369         result[i] = a[i] + b[i];
 
  374 template <
class T1, 
class T2, 
size_t N1, 
size_t N2>
 
  375 Array<decltype(T1{} + T2{}), N1> 
operator+(
const Array<T1, N1> &a,
 
  376                                            const Array<T2, N2> &b) {
 
  377     return a.
slice() + b.slice();
 
  381 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1,
 
  382           bool Reverse2, 
bool Const1, 
bool Const2>
 
  383 const ArraySlice<T1, N1, Reverse1, Const1> &
 
  386     static_assert(N1 == N2, 
"Error: sizes do not match");
 
  387     for (
size_t i = 0; i < N1; ++i)
 
  393 template <
class T1, 
class T2, 
size_t N1, 
size_t N2>
 
  402 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1,
 
  403           bool Reverse2, 
bool Const1, 
bool Const2>
 
  404 Array<decltype(T1{} - T2{}), N1>
 
  407     static_assert(N1 == N2, 
"Error: sizes do not match");
 
  408     Array<decltype(T1{} - T2{}), N1> result = {{}};
 
  409     for (
size_t i = 0; i < N1; ++i)
 
  410         result[i] = a[i] - b[i];
 
  415 template <
class T1, 
class T2, 
size_t N1, 
size_t N2>
 
  416 Array<decltype(T1{} - T2{}), N1> 
operator-(
const Array<T1, N1> &a,
 
  417                                            const Array<T2, N2> &b) {
 
  418     return a.
slice() - b.slice();
 
  422 template <
class T1, 
class T2, 
size_t N1, 
size_t N2, 
bool Reverse1,
 
  423           bool Reverse2, 
bool Const1, 
bool Const2>
 
  424 const ArraySlice<T1, N1, Reverse1, Const1> &
 
  427     static_assert(N1 == N2, 
"Error: sizes do not match");
 
  428     for (
size_t i = 0; i < N1; ++i)
 
  434 template <
class T1, 
class T2, 
size_t N1, 
size_t N2>
 
  443 template <
class T1, 
class T2, 
size_t N1, 
bool Reverse1, 
bool Const1>
 
  444 Array<decltype(T1{} * T2{}), N1>
 
  446     Array<decltype(T1{} * T2{}), N1> result = {{}};
 
  447     for (
size_t i = 0; i < N1; ++i)
 
  448         result[i] = a[i] * b;
 
  453 template <
class T1, 
class T2, 
size_t N1>
 
  454 Array<decltype(T1{} * T2{}), N1> 
operator*(
const Array<T1, N1> &a, T2 b) {
 
  455     return a.
slice() * b;
 
  459 template <
class T1, 
class T2, 
size_t N2, 
bool Reverse2, 
bool Const2>
 
  460 Array<decltype(T1{} * T2{}), N2>
 
  462     Array<decltype(T1{} * T2{}), N2> result = {{}};
 
  463     for (
size_t i = 0; i < N2; ++i)
 
  464         result[i] = a * b[i];
 
  469 template <
class T1, 
class T2, 
size_t N2>
 
  470 Array<decltype(T1{} * T2{}), N2> 
operator*(T1 a, 
const Array<T2, N2> &b) {
 
  471     return a * b.
slice();
 
  475 template <
class T1, 
class T2, 
size_t N1, 
bool Reverse1, 
bool Const1>
 
  476 const ArraySlice<T1, N1, Reverse1, Const1> &
 
  478     for (
size_t i = 0; i < N1; ++i)
 
  484 template <
class T1, 
class T2, 
size_t N1>
 
  493 template <
class T1, 
class T2, 
size_t N1, 
bool Reverse1, 
bool Const1>
 
  494 Array<decltype(T1{} / T2{}), N1>
 
  496     Array<decltype(T1{} / T2{}), N1> result = {{}};
 
  497     for (
size_t i = 0; i < N1; ++i)
 
  498         result[i] = a[i] / b;
 
  503 template <
class T1, 
class T2, 
size_t N1>
 
  504 Array<decltype(T1{} / T2{}), N1> 
operator/(
const Array<T1, N1> &a, T2 b) {
 
  505     return a.
slice() / b;
 
  509 template <
class T1, 
class T2, 
size_t N1, 
bool Reverse1, 
bool Const1>
 
  510 const ArraySlice<T1, N1, Reverse1, Const1> &
 
  512     for (
size_t i = 0; i < N1; ++i)
 
  518 template <
class T1, 
class T2, 
size_t N1>
 
  527 template <
class T, 
size_t N, 
bool Reverse, 
bool Const>
 
  528 Array<decltype(-T{}), N> 
operator-(ArraySlice<T, N, Reverse, Const> a) {
 
  529     Array<decltype(-T{}), N> result = {{}};
 
  530     for (
size_t i = 0; i < N; ++i)
 
  536 template <
class T, 
size_t N>
 
  537 Array<decltype(-T{}), N> 
operator-(
const Array<T, N> &a) {
 
  544 template <
class T, 
size_t nb_rows, 
size_t nb_cols>
 
  
bool operator!=(Iterator rhs) const
 
difference_type operator-(Iterator rhs) const
 
bool operator==(Iterator rhs) const
 
T * end()
Get a pointer to the memory beyond the array.
 
typename std::conditional< Const, const T *, T * >::type ElementPtrType
 
const T * end() const
Get a pointer to the memory beyond the array.
 
std::ptrdiff_t difference_type
 
Array< T1, N1 > & operator*=(Array< T1, N1 > &a, T2 b)
Array *= Scalar.
 
bool operator<=(Iterator rhs) const
 
ArraySlice(ElementPtrType array)
Constructor.
 
Array< T, N > asArray() const
 
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), false > slice()
Get a view on a slice of the Array.
 
#define AH_DIAGNOSTIC_POP()
 
const T & operator[](size_t index) const
Get the element at the given index.
 
Array< T1, N1 > & operator-=(Array< T1, N1 > &a, const Array< T2, N2 > &b)
Array -= Array.
 
Iterator operator+(difference_type rhs) const
 
reference operator*() const
 
Array< T1, N1 > & operator/=(Array< T1, N1 > &a, T2 b)
Array /= Scalar.
 
#define ERROR(msg, errc)
Print the error message and error code, and stop the execution if FATAL_ERRORS are enabled.
 
ArraySlice< T, abs_diff(End, Start)+1, Reverse ^(End< Start), Const > slice() const
 
std::random_access_iterator_tag iterator_category
 
An array wrapper for easy copying, comparing, and iterating.
 
ElementRefType operator[](size_t index) const
Get the element at the given index.
 
bool operator==(const Array< T, N > &rhs) const
Check the equality of all elements in two arrays.
 
bool operator<(Iterator rhs) const
 
T * begin()
Get a pointer to the first element.
 
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), true > slice() const
Get a read-only view on a slice of the Array.
 
Iterator(ElementPtrType ptr)
 
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), true > cslice() const
Get a read-only view on a slice of the Array.
 
Array< T1, N1 > & operator+=(Array< T1, N1 > &a, const Array< T2, N2 > &b)
Array += Array.
 
Class for a view on a slice of an array.
 
Iterator operator-(difference_type rhs) const
 
constexpr T abs_diff(const T &a, const T &b)
 
T & operator[](size_t index)
Get the element at the given index.
 
#define AH_DIAGNOSTIC_WERROR()
 
#define BEGIN_AH_NAMESPACE
 
bool operator!=(ArraySlice< T1, N1, Reverse1, Const1 > a, const Array< T2, N2 > &b)
Slice != Array.
 
bool operator!=(const Array< T, N > &rhs) const
Check the inequality of all elements in two arrays.
 
typename std::conditional< Const, const T &, T & >::type ElementRefType
 
const T * begin() const
Get a pointer to the first element.
 
bool operator==(ArraySlice< T1, N1, Reverse1, Const1 > a, const Array< T2, N2 > &b)
Slice == Array.