Boost logo

Boost Users :

Subject: Re: [Boost-users] c++: boost::multi_array - initialize a multi_array
From: Rhys Ulerich (rhys.ulerich_at_[hidden])
Date: 2009-12-30 12:54:57

> i am trying to initialize all the elements in boost::multi_array type to
> zero, so far, with out success. At tried using std::fill for 1-dim
> boost::multi_array and it worked. Once i tried std:fill on 2-dim
> boost::multi_array it haven't worked any more.

One approach is the use multi_array::data() and
multi_array::num_elements() to get pointer-based iterators to the
underlying raw storage:

    boost::multi_array<unsigned int, 1> foo( boost::extents[10] );
    std::fill(, + foo.num_elements(), 0 );

    boost::multi_array<unsigned int, 2> boo( boost::extents[10][79] );
    std::fill(, + boo.num_elements(), 0 );

Another approach would be to use multi_array's assign member function.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at