[英]Iterating a boost multi_array
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.
我有一个N X M的2D数组,当前存储在boost multi_array中。 The N columns represent spatial dimensions eg x,y,z and the M rows are points along each dimension.
N列表示空间尺寸,例如x,y,z,M行是沿每个尺寸的点。
What I would like to do is print all possible combinations of points along each 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.
我尝试使用迭代器并将元素作为A [i] [j]访问,但是没有运气。 Anyone have any suggestions or thoughts?
有人有什么建议或想法吗?
You're likely not resetting the iterators by setting them back to begin(). 您可能不会通过将迭代器设置回begin()来重置迭代器。 A better strategy is not reusing the iterators at all.
更好的策略是根本不重用迭代器。 Make them local to the loop that you're using them in.
使它们位于您正在使用它们的循环的本地。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.