Boost logo

Boost :

From: Roland (roland.richter_at_[hidden])
Date: 2002-03-22 08:42:14


Hi boosters,

I recently noticed that adapted iterators (such as transform_iterator)
might be considered as "equal" even if, when dereferenced, they yield
different values:

  int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 };

  typedef std::binder1st< std::multiplies<int> > Function;
  typedef boost::transform_iterator_generator<Function, int*>::type doubling_iterator;

  doubling_iterator i(x, std::bind1st(std::multiplies<int>(), 2));
  doubling_iterator j(x, std::bind1st(std::multiplies<int>(), 3)); // Somebody wants more

Whoops!
We have the odd situation that i == j (since both iterators point to the
same location), but that *i != *j (because dereferencing involves a call
of transform_iterators' functions; these are different, however
transform_iterator_policy does not care about that).

I guess this behaviour is okay, since two iterators can be considered
"equal" if they point to the same position (SGI's STL documentation is
not very precise on that issue); and if somebody wants
the dereferenced values to be equal, he can check for that explicitly.

However, I think that this is a somehow subtle point, and should perhaps
be mentioned in the documentation.

- Roland


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