6#include <AH/STL/iterator>
7#include <AH/STL/type_traits>
14 return a < b ? b -
a :
a - b;
20template <
class T,
size_t N,
bool Reverse,
bool Const>
31template <
class T,
size_t N>
35 constexpr static size_t length = N;
48 ERROR(F(
"Index out of bounds: ") << index << F(
" ≥ ") << N, 0xEDED);
65 ERROR(F(
"Index out of bounds: ") << index << F(
" ≥ ") << N, 0xEDED);
79 const T *
begin()
const {
return &data[0]; }
84 T *
end() {
return &data[N]; }
89 const T *
end()
const {
return &data[N]; }
100 for (
size_t i = 0;
i < N;
i++)
101 if ((*
this)[
i] !=
rhs[
i])
126 template <
size_t Start = 0,
size_t End = N - 1>
133 template <
size_t Start = 0,
size_t End = N - 1>
140 template <
size_t Start = 0,
size_t End = N - 1>
163template <
class T,
size_t N,
bool Reverse = false,
bool Const = true>
166 typename std::conditional<Const, const T &, T &>::type;
168 typename std::conditional<Const, const T *, T *>::type;
179 for (
size_t i = 0;
i < N; ++
i)
180 slice[
i] = (*
this)[
i];
198 ERROR(F(
"Index out of bounds: ") << index << F(
" ≥ ") << N, 0xEDEF);
202 return *(array - index);
204 return *(array + index);
221 template <
size_t Start,
size_t End>
229template <
class T,
size_t N>
230template <
size_t Start,
size_t End>
233 static_assert(
Start < N,
"");
234 static_assert(
End < N,
"");
235 return &(*this)[
Start];
238template <
class T,
size_t N>
239template <
size_t Start,
size_t End>
242 static_assert(
Start < N,
"");
243 static_assert(
End < N,
"");
244 return &(*this)[
Start];
247template <
class T,
size_t N,
bool Reverse,
bool Const>
248template <
size_t Start,
size_t End>
251 static_assert(
Start < N,
"");
252 static_assert(
End < N,
"");
253 return &(*this)[
Start];
257template <
class T,
size_t N,
bool Reverse,
bool Const>
272 static_assert(
N1 ==
N2,
"Error: sizes do not match");
273 for (
size_t i = 0;
i <
N1; ++
i)
281template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse2,
bool Const2>
284 return a.slice() == b;
289template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse1,
bool Const1>
308template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse2,
bool Const2>
311 return a.slice() != b;
316template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse1,
bool Const1>
331 static_assert(
N1 ==
N2,
"Error: sizes do not match");
333 for (
size_t i = 0;
i <
N1; ++
i)
340template <
class T1,
class T2,
size_t N1,
size_t N2>
353 static_assert(
N1 ==
N2,
"Error: sizes do not match");
354 for (
size_t i = 0;
i <
N1; ++
i)
361template <
class T1,
class T2,
size_t N1,
size_t N2>
376 static_assert(
N1 ==
N2,
"Error: sizes do not match");
378 for (
size_t i = 0;
i <
N1; ++
i)
385template <
class T1,
class T2,
size_t N1,
size_t N2>
398 static_assert(
N1 ==
N2,
"Error: sizes do not match");
399 for (
size_t i = 0;
i <
N1; ++
i)
406template <
class T1,
class T2,
size_t N1,
size_t N2>
416template <
class T1,
class T2,
size_t N1,
bool Reverse1,
bool Const1>
420 for (
size_t i = 0;
i <
N1; ++
i)
427template <
class T1,
class T2,
size_t N1>
434template <
class T1,
class T2,
size_t N2,
bool Reverse2,
bool Const2>
438 for (
size_t i = 0;
i <
N2; ++
i)
445template <
class T1,
class T2,
size_t N2>
452template <
class T1,
class T2,
size_t N1,
bool Reverse1,
bool Const1>
455 for (
size_t i = 0;
i <
N1; ++
i)
462template <
class T1,
class T2,
size_t N1>
472template <
class T1,
class T2,
size_t N1,
bool Reverse1,
bool Const1>
476 for (
size_t i = 0;
i <
N1; ++
i)
483template <
class T1,
class T2,
size_t N1>
490template <
class T1,
class T2,
size_t N1,
bool Reverse1,
bool Const1>
493 for (
size_t i = 0;
i <
N1; ++
i)
500template <
class T1,
class T2,
size_t N1>
510template <
class T,
size_t N,
bool Reverse,
bool Const>
513 for (
size_t i = 0;
i < N; ++
i)
520template <
class T,
size_t N>
528template <
class T,
size_t NumRows,
size_t NumCols>
#define BEGIN_AH_NAMESPACE
@ Start
Start System Real-Time message.
Class for a view on a slice of an array.
typename std::conditional< Const, const T *, T * >::type ElementPtrType
typename std::conditional< Reverse, std::reverse_iterator< ElementPtrType >, ElementPtrType >::type iterator
ArraySlice(ElementPtrType array)
Constructor.
typename std::conditional< Const, const T &, T & >::type ElementRefType
ElementRefType operator[](size_t index) const
Get the element at the given index.
Array< T, N > asArray() const
ArraySlice< T, abs_diff(End, Start)+1, Reverse ^(End< Start), Const > slice() const
Array< T1, N1 > & operator*=(Array< T1, N1 > &a, T2 b)
Array *= Scalar.
bool operator!=(ArraySlice< T1, N1, Reverse1, Const1 > a, ArraySlice< T2, N2, Reverse2, Const2 > b)
Slice != Slice.
const ArraySlice< T1, N1, Reverse1, Const1 > & operator+=(const ArraySlice< T1, N1, Reverse1, Const1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
Slice += Slice.
const ArraySlice< T1, N1, Reverse1, Const1 > & operator*=(const ArraySlice< T1, N1, Reverse1, Const1 > &a, T2 b)
Slice *= Scalar.
const ArraySlice< T1, N1, Reverse1, Const1 > & operator/=(const ArraySlice< T1, N1, Reverse1, Const1 > &a, T2 b)
Slice /= Scalar.
bool operator!=(const Array< T1, N1 > &a, ArraySlice< T2, N2, Reverse2, Const2 > b)
Array != Slice.
bool operator==(const Array< T1, N1 > &a, ArraySlice< T2, N2, Reverse2, Const2 > b)
Array == Slice.
Array< T1, N1 > & operator+=(Array< T1, N1 > &a, const Array< T2, N2 > &b)
Array += Array.
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
bool operator==(ArraySlice< T1, N1, Reverse1, Const1 > a, ArraySlice< T2, N2, Reverse2, Const2 > b)
Slice == Slice.
bool operator==(ArraySlice< T1, N1, Reverse1, Const1 > a, const Array< T2, N2 > &b)
Slice == Array.
const ArraySlice< T1, N1, Reverse1, Const1 > & operator-=(const ArraySlice< T1, N1, Reverse1, Const1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
Slice -= Slice.
Array< T1, N1 > & operator/=(Array< T1, N1 > &a, T2 b)
Array /= Scalar.
bool operator!=(ArraySlice< T1, N1, Reverse1, Const1 > a, const Array< T2, N2 > &b)
Slice != Array.
Array< T1, N1 > & operator-=(Array< T1, N1 > &a, const Array< T2, N2 > &b)
Array -= Array.
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
constexpr T abs_diff(const T &a, const T &b)
An array wrapper for easy copying, comparing, and iterating.
const T * end() const
Get a pointer to the memory beyond the array.
T & operator[](size_t index)
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!=(const Array< T, N > &rhs) const
Check the inequality of all elements in two arrays.
T * begin()
Get a pointer to the first element.
T * end()
Get a pointer to the memory beyond the array.
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), true > cslice() const
Get a read-only view on a slice of the Array.
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), true > slice() const
Get a read-only view on a slice of the Array.
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), false > slice()
Get a view on a slice of the Array.
const T * begin() const
Get a pointer to the first element.
const T & operator[](size_t index) const
Get the element at the given index.