@Jeff
I really think this is an interesting question. I'm not sure how useful this is, but this is the right question.
@Ed
Can you provide a little more information on this? You said that the size of the array is dynamic, but also the number of dynamic elements?
EDITOR: I’ll try to answer the question anyway. I can’t give you the code from the top of my head (it will take some time to get this right without the compiler here on this PC), but I can point you in the right direction ...
As an example, you can use 8 dimensions (0-7) with indices from 0 to 3. You only care about 1,2 and 6. This means that you have two arrays. First, array_care[4][4][4] for 1,2 and 6. array_care[4][4][4] will contain the final result.
Next, we want to iterate in a very specific way. We have an input[4][4][4][4][4][4][4][4] array for analysis, and we take care of sizes 1, 2 and 6.
We need to define some temporary indexes:
int dim[8] = {0,0,0,0,0,0,0,0};
We also need to keep the order in which we want to increase the indices:
int increase_index_order[8] = {7,5,4,3,0,6,2,1}; int i = 0;
This order is important to fulfill your requests.
Define a completion flag:
bool terminate=false;
Now we can create our loop:
while (terminate) { array_care[dim[1]][dim[2]][dim[6]] += input[dim[0]][dim[1]][dim[2]][dim[3]][dim[4]][dim[5]][dim[6]][dim[7]]; while ((dim[increase_index_order[i]] = 3) && (i < 8)) { dim[increase_index_order[i]]=0; i++; } if (i < 8) { dim[increase_index_order[i]]++; i=0; } else { terminate=true; } }
This should work on 8 dimensions, taking care of 3 dimensions. It takes a little longer to make it dynamic, and I don't have time. Hope this helps. I apologize, but have not yet studied the code. :(