Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-03-24 14:02:32

On Fri, 23 Mar 2001, Michael D. Crawford wrote:
crawfo> // Alternatively, if iterator support is built into ZDCPixmap then we can
crawfo> // initialize from a member function that returns an iterator:
crawfo> //
crawfo> // PixelIterator iter( myPix.TopLeft() );

An alternative that avoids touching the existing XDCPixmap is to
write TopLeft as a free function instead of a member function.

PixelIterator iter = top_left(myPix);

crawfo> But there's a problem - how can they be used two-dimensionally in a loop? One
crawfo> can only loop over one index at a time. One possible solution although a
crawfo> little ugly is to put inner loop iterators inside to limit loops

There's a couple more alternatives here.

1. Use two iterators, the "outer iterator" iterates over rows
of the image, and the "inner iterator" iterates down each row.

PixelRowIterator row_iter = rows_begin(myPix);
for (; row_iter != rows_end(myPix); ++row_iter) {
  PixelIterator iter = begin(*row_iter);
  for (; iter != end(*row_iter); ++iter)

MTL provides this kind of interface for matrices.

2. Use a single iterator that knows how to wrap around. The
 problem with this approach is that it introduces and if statement
 into the inner loop, which hurts performance.


 Jeremy Siek www:
 Ph.D. Candidate email: jsiek_at_[hidden]
 Univ. of Notre Dame work phone: (219) 631-3906

Boost list run by bdawes at, gregod at, cpdaniel at, john at