Boost logo

Boost Users :

Subject: Re: [Boost-users] [MultiArray] subscript to index
From: Sami (randomaccessiterator_at_[hidden])
Date: 2010-05-03 23:20:04


On Sat, May 1, 2010 at 9:08 AM, Rhys Ulerich <rhys.ulerich_at_[hidden]> wrote:

>
> Not as far as I know. You could accomplish this accumulating indices
> and strides relative to the origin (similar to the pseudocode for
> a(index_list) in Table 3 of
> http://www.boost.org/doc/libs/1_42_0/libs/multi_array/doc/reference.html
> ).

 One other option might be &a(index_list) - a.origin().
>

... since origin() is arr [0][0]...[0], neither of these is the answer in
general. But thanks, good pointers there! Sad there isn't a
multi_array::offset( indices ) or something that:

assert (
   &arr( index_list ) == arr.data() + arr.*offset*( index_list )
 )

this kind of stuff is useful when interacting with legacy libs or other
languages.

On a separate note, since for whatever reason the multi_array::index_bases()
doesn't return a const Collection reference or something, the following
doesn't work:

T element = arr( arr.index_bases() );

Is there an easier alternative to the following (setting the first element
of any Multi Array model, note that data() may not be available for all):

indices I; // a collection object
for ( int i = 0; i < arr.num_dimensions(); ++i )
    I[i] = arr.index_bases()[i];

arr( I ) = ... ;



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