Boost logo

Boost Users :

From: François Duranleau (duranlef_at_[hidden])
Date: 2007-09-04 13:38:17


On Tue, 4 Sep 2007, Graham Reitz wrote:

> How do you access the data in the example below?
>
> Thanks much,
>
> Graham
>
> boost::multi_array<double,2> multi_test;
> boost::multi_array<double,2>::iterator multi_test_iter;
> boost::multi_array<double,2>::extent_gen extents;
>
> multi_test.resize(extents[2][3]);
>
> for (multi_test_iter = multi_test.begin();
> multi_test_iter != multi_test.end(); ++multi_test_iter)
> {
> // How do you get(set) at the current data set pointed to by multi_test_iter?
> }

multi_test_iter in this example is an iterator on rows. You need to add an
extra loop to iterate on those elements, something like

for ( multi_test_iter = multi_test.begin() ;
       multi_test_iter != multi_test.end() ;
       ++ multi_test_iter )
{
     for ( boost::multi_array< double , 2 >::value_type::iterator
             inner_multi_test_iter = multi_test_iter->begin() ,
             end_inner = multi_test_iter->end() ;
           inner_multi_test_iter != end_inner ;
           ++ inner_multi_test_iter )
     {
         // here, *inner_mult_test_iter returns a reference to a double
     }
}

-- 
François Duranleau

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net