我有一个整数N,我在编译时知道.我还有一个std :: array,它包含描述N维数组形状的整数.我想在编译时使用元编程技术生成嵌套循环,如下所述.
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 < shape[1]; j++) {
for(int k = 0; k < shape[2]; k++) {
for(int l = 0; l < shape[3]; l++) …Run Code Online (Sandbox Code Playgroud)