简体   繁体   中英

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:

Using std:vector, I can assign between vector elements via an iterator:

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:

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. What am I missing?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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