Boost logo

Boost Users :

From: Cromwell Enage (sponage_at_[hidden])
Date: 2006-06-29 16:46:17


--- Sohail Somani wrote:
> > -----Original Message-----
> > On Behalf Of Baranowski, Daniel
> [snip]
> > Basically, I have a 2 Dimensional array and I
> > would like to be able to access the center of
> > that array using a variable that maps to some
> > index (for example, element[3][3] in a 7x7
> > array).
> [snip]
>
> Would T & center = element[3][3] be satisfactory?

Try:

typename boost::multi_array<T,2>::index
   index1 = (element.index_bases()[0]
          + element.strides()[0]) / 2;
typename boost::multi_array<T,2>::index
   index2 = element.index_bases()[1];
          + element.strides()[1]) / 2;
T& center = element[index1][index2];

> I don't think multiarray supports any type of
> reallocation after construction, so it should
> be ok.

boost::multi_array has a resize() function, if that's
what you're afraid of. See
<http://www.boost.org/libs/multi_array/doc/reference.html>

                              Cromwell D. Enage

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


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