10#include <AH/STL/algorithm>
12#if __cplusplus >= 201400L
13#define USE_CONSTEXPR_ARRAY_HELPERS constexpr
15#define USE_CONSTEXPR_ARRAY_HELPERS
31template <
class T,
class V>
67template <
class T,
size_t N,
class G>
70 std::generate(array.begin(), array.end(), generator);
87template <
size_t N,
class G>
89 ->
Array<
decltype(generator()), N> {
90 Array<
decltype(generator()), N> array{{}};
91 std::generate(array.begin(), array.end(), generator);
108template <
class T,
size_t N,
class U>
111 std::transform(std::begin(src), std::end(src), std::begin(dest),
112 [](
const U &src) {
return T(src); });
119template <
class F,
class U,
size_t N>
122 Array<
decltype(F{}(U{})), N> dest{{}};
123 std::transform(std::begin(src), std::end(src), std::begin(dest), f);
127#if !defined(__GNUC__) || (__GNUC__ > 7) || \
128 (__GNUC__ == 7 && __GNUC_MINOR__ >= 3) || defined(DOXYGEN)
132template <
class T,
size_t N,
class... Args>
134 return generateArray<N>([&]() {
return T{args...}; });
137template <
class T,
size_t N,
class... Args>
140 for (
auto &el : array)
178template <
class T,
size_t N,
class U,
class V = U>
182 return generateArray<T, N>(g);
200template <
class T,
size_t M,
size_t N>
205 for (
size_t i = 0; i < M; ++i, ++r)
207 for (
size_t i = 0; i < N; ++i, ++r)
212template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse1,
213 bool Reverse2,
bool Const1,
bool Const2>
217 Array<
decltype(T1() * T2()), N1 + N2 - 1> result = {{}};
218 for (
size_t i = 0; i < N1; ++i)
219 for (
size_t j = 0; j < N2; ++j)
220 result[i + j] += a[i] * b[j];
224template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse1,
bool Const1>
231template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse2,
bool Const2>
238template <
class T1,
class T2,
size_t N1,
size_t N2>
252template <
class T,
size_t N,
bool Reverse,
bool Const>
253std::enable_if_t<std::is_arithmetic<T>::value, std::ostream &>
254operator<<(std::ostream &os,
const AH::ArraySlice<T, N, Reverse, Const> &a) {
255 for (
const T &el : a.template slice<0, N - 2>())
261template <
class T,
size_t N>
262std::enable_if_t<std::is_arithmetic<T>::value, std::ostream &>
263operator<<(std::ostream &os,
const AH::Array<T, N> &a) {
264 return os << a.slice();
271template <
class T,
size_t N,
bool Reverse,
bool Const>
272std::enable_if_t<std::is_arithmetic<T>::value, Print &>
273operator<<(Print &os,
const AH::ArraySlice<T, N, Reverse, Const> &a) {
274 for (
const T &el : a.template slice<0, N - 2>())
280template <
class T,
size_t N>
281std::enable_if_t<std::is_arithmetic<T>::value, Print &>
282operator<<(Print &os,
const AH::Array<T, N> &a) {
283 return os << a.slice();
#define USE_CONSTEXPR_ARRAY_HELPERS
#define BEGIN_AH_NAMESPACE
#define AH_DIAGNOSTIC_POP()
#define AH_DIAGNOSTIC_WERROR()
Class for a view on a slice of an array.
Utility class that acts as a functor to return incremental values.
Incrementor(T start=0, V increment=1)
Array< T, N > generateIncrementalArray(U start=0, V increment=V(1))
Generate an array where the first value is given, and the subsequent values are calculated as the pre...
Array< decltype(T1() *T2()), N1+N2 - 1 > distribute(const ArraySlice< T1, N1, Reverse1, Const1 > &a, const ArraySlice< T2, N2, Reverse2, Const2 > &b)
Array< T, N > copyAs(const Array< U, N > &src)
Copy an Array to an Array of a different type.
Array< T, N > fillArray(Args... args)
Fill the array with the same value for each element.
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), false > slice()
Get a view on a slice of the Array.
Array< decltype(F{}(U{})), N > apply(const Array< U, N > &src, F f)
Apply a function to all elements of the array and return a copy.
Array< T, N > generateArray(G generator)
Generate an array using the given generator.
Array< T, M+N > cat(const Array< T, M > &a, const Array< T, N > &b)
Concatenate two arrays.
Print & operator<<(Print &os, Quaternion e)
Printing.
An array wrapper for easy copying, comparing, and iterating.