Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-02-20 08:42:17

Christian Engström <christian.engstrom_at_[hidden]> writes:

> Class proxy_iterator
> To get operator-> working in the same way as for a Container<T>, we
> define the classes proxy_iterator and const_proxy_iterator.
> A proxy_iterator is publicly derived from the iterator of the
> underlying Container< proxy<T> >.

And if that iterator happens to be a pointer?

> It works just like standard iterator
> in all respects except one, which is that operator-> does a double
> dereferencing, so that it will deliver a pointer to the T object
> itself. This lets us use the -> operator in the same way that we would
> with a direct container. operator* is not changed, however, and
> retains its single dereferencing semantics.
> Are we really allowed to define these operators like this? --Yes, we are.

No you're not. The standard makes it very clear that the semantics of
an iterator's operator-> must correspond to those of its operator*.

The design makes several other wrong assumptions about iterator
requirements. I suggest checking out the Boost iterator library for
correct iterator construction. indirect_iterator may already suit
your needs.

Dave Abrahams
Boost Consulting

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