How to generate nested loops at compile time
问题 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 -dimensional array. I want to generate nested loops, as described bellow, at compile time, using metaprogramming techniques. constexpr int N {4}; constexpr std::array<int, N> shape {{1,3,5,2}}; auto f = [/* accept object which uses coords */] (auto... coords) { // do sth with coords }; // This is what I want to generate. for(int i = 0; i < shape[0]; i++) { for(int j = 0; j