On Fri, Oct 10, 2008 at 12:55 AM, Ronald Garcia <garcia@cs.indiana.edu> wrote:
Hi Robert,

The index_range object is used to create views, but it doesn't stay around.  However, all of the information from an index_range is still accessible.  You want to look into the following 3 MultiArray concept functions: indices(), strides(), and shape().

Based on your code,  it looks like you're trying to get the valid indices for the array so you can dereference it.

If you're not changing the index base (meaning your array indices always start at 0), then you want to write:

typedef Grid::array_view<2>::type view_t

...

for(view_t::index i = 0; i != view.size(); ++i) { ... }


Hi Ron

Thanks for your help - the solution you suggest will solve my immediate problem,
however I was  really looking for a more general solution. Looking through the reference,
AFAICS the only occurance of "indices" is as the global static index_gen<0,0> object.
Had this function been present as an member of multi_array it might reasonbly return
exactly the information I'm seeking.

Without making the assumption that my indices are zero based I think I can generally
write my loop as, (and please confirm this btw)

for (view_t::index i = * view.index_bases(); i != * view.shape(); ++i ) {.....}

but it seems a rather non-obvious and cumbersome expression. If view_t had
an indices() method that returned a list of index_range objects then I could
write

for(view_t::index i = view.indices()[0].start(); i != view.indices()[0].finish(); ++i ){.....}

which seems to be a more obvious syntax, and more suggestive of
looping over a range. Even better would be to support this syntax

for(view_t::index i=view.indices(0).start(); i != view.indices(0).finish(); ++i ) {.....}

Sorry if I'm covering old ground btw, but multi_array has been around in Boost for
rather longer than I have.

- Rob.