简体   繁体   English

使用boost multi_array迭代器在数组元素之间分配

[英]assignment between array elements using boost multi_array iterator

Working on a Kubuntu 14.04 system with gcc 4.8.4 I ran into the following problem: 使用gcc 4.8.4在Kubuntu 14.04系统上工作时,我遇到了以下问题:

Using std:vector, I can assign between vector elements via an iterator: 使用std:vector,我可以通过迭代器在矢量元素之间进行分配:

std::vector<float> v ;
v.push_back(0.0) ;
v.push_back(1.0) ;
auto vv = v.begin() ;
vv[0] = vv[1] ;
assert ( v[0] == v[1] ) ;

Using a boost multi_array, this fails: 使用boost multi_array,这将失败:

typedef boost::multi_array<float, 1> array_type; 
boost::array<array_type::index, 1> shape = {{ 2 }};
array_type a(shape) ;
a[0] = 0.0 ;
a[1] = 1.0 ;
auto aa = a.begin() ;
aa[0] = aa[1] ;
assert ( a[0] == a[1] ) ; // fails, a[0] is unmodified

I can work around this using a different idiom like 我可以使用其他习语来解决此问题

aa[0] = *(aa+1) ;

But the code I want to use with the multi_array is written using assignments of the type that doesn't work. 但是我要与multi_array一起使用的代码是使用无效类型的赋值编写的。 What am I missing? 我想念什么?

原因是boost::multi_array operator[]涉及的迭代器是输入迭代器 ,不需要是可变的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM