开发者

Iterating a boost multi_array

开发者 https://www.devze.com 2023-02-09 11:41 出处:网络
I am having a problem with what I think should be an easy piece of code. I have a 2D array that is N x M, currently stored in a boost multi_array. The N columns represent spatial dimensions e.g. x,y,z

I am having a problem with what I think should be an easy piece of code. I have a 2D array that is N x M, currently stored in a boost multi_array. The N columns represent spatial dimensions e.g. x,y,z and the M rows are points along each dimension.

What I would like to do is print all possible combinations of points along e开发者_JAVA百科ach dimension

For example, if my array is:

-1 -1
 1  1

I want to print:

-1 -1
 1 -1
-1  1
 1  1

I just cant make it work and I always go out of range on the array. I have tried using iterators and accessing the elements as A[i][j], but with no luck. Anyone have any suggestions or thoughts?


You're likely not resetting the iterators by setting them back to begin(). A better strategy is not reusing the iterators at all. Make them local to the loop that you're using them in.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号