Boost logo

Boost Users :

Subject: Re: [Boost-users] Multi-Array indexing
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-10-20 17:39:54


On Mon, Oct 20, 2008 at 8:37 PM, todd keeler <tkeeler_at_[hidden]> wrote:

> Hi, I'd like to understand how the Boost Multi-array implements multiple
> indexing using the regular square bracket operator.
>
> I've waded through the template code for a few hours, from what I
> understand, there's a nested bunch of sub-arrays which leads to a final
> object which offers a reference into the data array.
>
> I still can't figure out, however, how it solves this problem:
>
> Consider a Multi-Array A with dimension 3,
> Calling A[ i ][ j ][ k ]
> requires a call to
>
> A[ i ] which returns a Subarray, S1
>
> The subarray gets indexed
> S1[ j ] and another subarray S2 is returned.
>
> however S2[k] doesn't return a subarray, but a
> reference to the data in the multiarray.
>
> However, S1 and S2 are the same object (subarray), hence require the same
> overloaded operator, returning the same type.
> making this unfeasible.
>
> Therefore, the only way I can think to eliminate this dilemma is to have a
> different object type for every dimension. I'm not sure if this is what
> Multi-array does, but I'd sure like to know how it's done .
>
>
The subarrays S1 & S2 are instantiations of the same template, but with
different instantiation parameters (ie.,
the dimensionality of the subarray), and so are different types, for which
overload resolution works in the
normal way.

Regards, Rob.



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