Boost logo

Boost Users :

From: François Duranleau (duranlef_at_[hidden])
Date: 2006-02-03 12:42:04


On Thu, 2 Feb 2006, graphicsMan69 (sent by Nabble.com) wrote:

>
> Hi all -
>
> My basic need is to step through a portion of my multiarray at runtime.
> I don't know the dimension apriori, since the class I'm writing is
> templatized on dimension. This means that the multiarray can serve my
> other purposes just fine, since the dimesion is compile time constant,
> but I don't know the number of [] and the nesting of loops I'll need to
> iterate through the valid indices in my range min to max in my
> multiarray.
>
> Essentially, if I could specify a view of my multiarray, likely it
> shouldn't be too hard to iterate through the elements of that
> sub-multiarray, even without knowing the dimension at coding time.
>
> Anyone know of a way to get a view without knowing the dimensions at
> coding time?

I came across similar problems with boost::multi_array. I wanted to
iterate on all cells of just a portion of the whole multi_array. The way I
solved the problem was to use operator() instead of operator[], and a
multi-dimensional counting iterator (e.g.
http://www-etud.iro.umontreal.ca/~duranlef/code/multi_counting_iterator.hpp).
I am not convinced it is the most efficient way (or event elegant), but it
works very well to make an abstraction of the multi_array's dimension.

-- 
François Duranleau
LIGUM, Université de Montréal
"'Reality' is the temporary resultant of continuous struggles between
  rival gangs of programmers."
                           - Robert Anton Wilson, _Prometheus Rising_, 1983

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