Boost logo

Boost :

From: Giovanni Bavestrelli (giovanni.bavestrelli_at_[hidden])
Date: 2000-11-29 13:48:11


>Jeremy Siek writes:

>One area of expansion: from a quick glance at your article
>I gather the iterator interface allows for traversal of the
>whole array. It would also be nice to traverse through
>arbitrary one-dimensional slices of the array using iterator.

>Kevlin Henney also writes:

>Like Jeremy, I would like to see iteration through dimensional
>slices of the array. I also think it is worth generalising it
>down to a single dimension.

This kind of iteration is already possible in my Array as it is,
since each SubArray has iterators, with their begin and end member
functions. So, if you have a 3 dimensional array, you can traverse
dimensions like this:

Array<int,3> A3(ArraySizes(10)(20)(30)); // 3D Array of ints

// Traverse through a monodimensional slice within the 3D array
for (Array<int,1>::iterator i=A3[0][1].begin(),z=A3[0][1].end();i!
=z;i++)
       *i=1;

// Traverse through a bidimensional slice within the 3D array
for (Array<int,2>::iterator i=A3[0].begin(), z=A3[0].end();i!=z;i++)
       *i=1;

// Traverse through the complete 3D array
for (Array<int,3>::iterator i=A3.begin(),z=A3.end();i!=z;i++)
       *i=1;

You can actually mix iterators, starting on a bidimensional slice and
ending on a monodimensional part of it, but I would not recommend it,
since it's not very intuitive. You can obviously also use int*
instead of the various iterator definitions, as all iterators are
pointers. I did leave out reverse iteratars, though, for now.

Thanks for your comments!

Giovanni


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk