problems with boot::multi_array and standard algorithms
I cant get boost::multi_array to wrk with STL algorithms. In particular boost::multi_array<int,2> test_array( boost::extents[10][10] ); std::fill(test_array.begin(),test_array.end(),1); gives me the following compile errors. c:\Documents and Settings\b4edhdwj\My Documents\Projects\Libraries\boost_1_31_0\boost\multi_array\subarray.hpp(274 ) : error C2228: left of '.num_dimensions' must have class/struct/union type type is 'const int' c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\xutility(1136) : see reference to function template instantiation 'boost::detail::multi_array::sub_array<T,NumDims> &boost::detail::multi_array::sub_array<T,NumDims>::operator =<_Ty>(const ConstMultiArray &)' being compiled with [ T=int, NumDims=1, _Ty=int, ConstMultiArray=int ] c:\Documents and Settings\b4edhdwj\My Documents\Projects\BoostMatrix\BoostMatrix.cpp(93) : see reference to function template instantiation 'void std::fill<boost::multi_array_ref<T,NumDims>::iterator,int>(_FwdIt,_FwdIt,con st _Ty &)' being compiled with [ T=int, NumDims=2, _FwdIt=boost::multi_array_ref<int,2>::iterator, _Ty=int ] c:\Documents and Settings\b4edhdwj\My Documents\Projects\Libraries\boost_1_31_0\boost\multi_array\subarray.hpp(275 ) : error C2228: left of '.shape' must have class/struct/union type type is 'const int' c:\Documents and Settings\b4edhdwj\My Documents\Projects\Libraries\boost_1_31_0\boost\multi_array\subarray.hpp(275 ) : error C2228: left of '.shape' must have class/struct/union type type is 'const int' c:\Documents and Settings\b4edhdwj\My Documents\Projects\Libraries\boost_1_31_0\boost\multi_array\subarray.hpp(278 ) : error C2228: left of '.begin' must have class/struct/union type type is 'const int' c:\Documents and Settings\b4edhdwj\My Documents\Projects\Libraries\boost_1_31_0\boost\multi_array\subarray.hpp(278 ) : error C2228: left of '.end' must have class/struct/union type type is 'const int' Do the provided iterators not work for stl algorithms?
Hi Donald, On Feb 1, 2005, at 4:50 PM, Donald Johnson wrote:
I cant get boost::multi_array to wrk with STL algorithms. In particular
boost::multi_array<int,2> test_array( boost::extents[10][10] ); std::fill(test_array.begin(),test_array.end(),1);
gives me the following compile errors.
...
Do the provided iterators not work for stl algorithms?
Yes they do, but not in the manner that you think they do :). In the code above, you are creating a 2 dimensional array. Calling begin() on your array results in an iterator over the /one-dimensional arrays/ contained therein. Your code is trying to assign scalar values to one-dimensional arrays, hence the type error. You can get the effect that you are going for as follows. std:: fill(test_array.data(),test_array.data()+test_array.num_elements(),1); Hope this helps! ron
G'day all. Quoting Ronald Garcia <garcia@cs.indiana.edu>:
Yes they do, but not in the manner that you think they do :). In the code above, you are creating a 2 dimensional array. Calling begin() on your array results in an iterator over the /one-dimensional arrays/ contained therein. Your code is trying to assign scalar values to one-dimensional arrays, hence the type error. You can get the effect that you are going for as follows.
std:: fill(test_array.data(),test_array.data()+test_array.num_elements(),1);
Which reminds me of a question I've been meaning to ask... Any tips for dimension-independent programming with boost::multi_array? In particular, it would be really nice to be able to iterate over the elements in multi_array in such a way that the iterator also keeps track of the index. (This is for a real-world problem; I need to solve Poisson-esque problems on regular grids, and it would be handy if I could get it happening in either 2D or 3D by changing one template argument.) Cheers, Andrew Bromage
participants (3)
-
ajb@spamcop.net
-
Donald Johnson
-
Ronald Garcia