[multi_array] How to use std algorithms, like for_each?
Hi there, I'm a little confused by the documentation of the multi_array lib. The begin() is supposed to return an iterator, but dereferencing doesn't resolve into the value type. This makes it a little complicated to use multi_arrays with standard algorithms. Please consider the following code snippet which wont compile on VC 7.1. class tVoxel { public: typedef short tValue; tVoxel(): _oValue( 0 ) {} tVoxel(tValue oValue): _oValue( oValue ) {} void set( const tValue& oValue ) { _oValue = oValue; } tValue& get() { return _oValue; } const tValue& get() const { return _oValue; } private: tValue _oValue; }; int _tmain(int argc, _TCHAR* argv[]) { typedef boost::multi_array<tVoxel, 3> tVolume; tVolume oVolume( boost::extents[3][3][3] ); tVolume::const_iterator iVoxel = oVolume.begin(); tVolume::const_iterator iVoxelEnd = oVolume.end(); const tVoxel& oVoxel = iVoxel->get(); return 0; } The error message goes like: error C2039: 'get' : is not a member of 'boost::detail::multi_array::const_sub_array<T,NumDims>' with [ T=tVoxel, NumDims=2 ] Do I miss something important, here? Thanks for your help, Christian
Use origin() if you you want to go straight to the element level, or alternatively define a one-dimensional view of your liking and use begin() (not clear from your code what you are trying to achieve, but iVoxel = oVolume.origin() should do it). I hope this helps Antonio On 3/5/06, Christian Henning <chhenning@gmail.com> wrote:
Hi there, I'm a little confused by the documentation of the multi_array lib. The begin() is supposed to return an iterator, but dereferencing doesn't resolve into the value type. This makes it a little complicated to use multi_arrays with standard algorithms. Please consider the following code snippet which wont compile on VC 7.1.
class tVoxel { public:
typedef short tValue;
tVoxel(): _oValue( 0 ) {} tVoxel(tValue oValue): _oValue( oValue ) {}
void set( const tValue& oValue ) { _oValue = oValue; }
tValue& get() { return _oValue; } const tValue& get() const { return _oValue; }
private:
tValue _oValue; };
int _tmain(int argc, _TCHAR* argv[]) { typedef boost::multi_array<tVoxel, 3> tVolume;
tVolume oVolume( boost::extents[3][3][3] );
tVolume::const_iterator iVoxel = oVolume.begin(); tVolume::const_iterator iVoxelEnd = oVolume.end();
const tVoxel& oVoxel = iVoxel->get();
return 0; }
The error message goes like:
error C2039: 'get' : is not a member of 'boost::detail::multi_array::const_sub_array<T,NumDims>' with [ T=tVoxel, NumDims=2 ]
Do I miss something important, here?
Thanks for your help, Christian
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Antonio Piccolboni
-
Christian Henning