I have an integer N which I know at compile time. I also have an std::array holding integers describing the shape of an N-dime
Something like this (NOTE: I take the "shape" as a variadic template argument set..)
#include
template
struct Looper{
template
constexpr void operator()(F& f, X... x) {
for (int i = 0; i < I; ++i) {
Looper()(f, x..., i);
}
}
};
template
struct Looper{
template
constexpr void operator()(F& f, X... x) {
for (int i = 0; i < I; ++i) {
f(x..., i);
}
}
};
int main()
{
int v = 0;
auto f = [&](int i, int j, int k, int l) {
v += i + j + k + l;
};
Looper<1, 3, 5, 2>()(f);
auto g = [&](int i) {
v += i;
};
Looper<5>()(g);
std::cout << v << std::endl;
}