6#include <AH/STL/algorithm>
8#if __cplusplus >= 201400L
9#define USE_CONSTEXPR_ARRAY_HELPERS constexpr
11#define USE_CONSTEXPR_ARRAY_HELPERS
27template <
class T,
class V>
63template <
class T,
size_t N,
class G>
66 std::generate(array.begin(), array.end(), generator);
83template <
size_t N,
class G>
85 ->
Array<
decltype(generator()), N> {
86 Array<
decltype(generator()), N> array{{}};
87 std::generate(array.begin(), array.end(), generator);
104template <
class T,
size_t N,
class U>
107 std::transform(std::begin(src), std::end(src), std::begin(dest),
108 [](
const U &src) {
return T(src); });
115template <
class F,
class U,
size_t N>
118 Array<
decltype(F{}(U{})), N> dest{{}};
119 std::transform(std::begin(src), std::end(src), std::begin(dest), f);
123#if !defined(__GNUC__) || (__GNUC__ > 7) || \
124 (__GNUC__ == 7 && __GNUC_MINOR__ >= 3) || defined(DOXYGEN)
128template <
class T,
size_t N,
class... Args>
130 return generateArray<N>([&]() {
return T{args...}; });
133template <
class T,
size_t N,
class... Args>
136 for (
auto &el : array)
174template <
class T,
size_t N,
class U,
class V = U>
178 return generateArray<T, N>(g);
196template <
class T,
size_t M,
size_t N>
201 for (
size_t i = 0; i < M; ++i, ++r)
203 for (
size_t i = 0; i < N; ++i, ++r)
208template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse1,
209 bool Reverse2,
bool Const1,
bool Const2>
213 Array<
decltype(T1() * T2()), N1 + N2 - 1> result = {{}};
214 for (
size_t i = 0; i < N1; ++i)
215 for (
size_t j = 0; j < N2; ++j)
216 result[i + j] += a[i] * b[j];
220template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse1,
bool Const1>
227template <
class T1,
class T2,
size_t N1,
size_t N2,
bool Reverse2,
bool Const2>
234template <
class T1,
class T2,
size_t N1,
size_t N2>
250template <
class T,
size_t N,
bool Reverse,
bool Const>
251std::enable_if_t<std::is_arithmetic<T>::value, std::ostream &>
252operator<<(std::ostream &os,
const AH::ArraySlice<T, N, Reverse, Const> &a) {
253 for (
const T &el : a.template slice<0, N - 2>())
259template <
class T,
size_t N>
260std::enable_if_t<std::is_arithmetic<T>::value, std::ostream &>
261operator<<(std::ostream &os,
const AH::Array<T, N> &a) {
262 return os << a.slice();
273template <
class T,
size_t N,
bool Reverse,
bool Const>
274std::enable_if_t<std::is_arithmetic<T>::value, Print &>
275operator<<(Print &os,
const AH::ArraySlice<T, N, Reverse, Const> &a) {
276 for (
const T &el : a.template slice<0, N - 2>())
282template <
class T,
size_t N>
283std::enable_if_t<std::is_arithmetic<T>::value, Print &>
284operator<<(Print &os,
const AH::Array<T, N> &a) {
285 return os << a.slice();
#define USE_CONSTEXPR_ARRAY_HELPERS
#define BEGIN_AH_NAMESPACE
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.
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.
ArraySlice< T, abs_diff(Start, End)+1,(End< Start), false > slice()
Get a view on a slice of the Array.