Boost logo

Boost :

From: Thomas Witt (witt_at_[hidden])
Date: 2005-09-01 23:50:44


Neal Becker wrote:
> I see I can get this to work by adding an ugly const_cast. This seems to
> confirm my suspicion, that the problem is caused by iterator_facade having
> template <class Facade>
> static typename Facade::reference dereference(Facade const& f)
> {
> return f.dereference();
> }

Well the easy answer is this code is correct, it's your fault. Seriously
dereferencing an iterator is a const operation it does not change the
iterator state, even if the value the iterator points to can be changed
this way.

The state of the iterator is the position in the sequence it points to.
If the iterator is const you can not change the position but still the
object (if there is one) it points to.

The mapping to pointer types in pseudocode

iterator it; -> int* p;
iterator const cit; -> int* const const_p;
const_iterator it_to_const; -> int const* p_to_const;
const_iterator const cit_to_const; -> int const* const const_p_to_const;

The main difference being that the fact whether the iterator points to
something const is molded into it's type while it's a qualifier in the
formulation of the pointer type. Note that iterator/const_iterator is
only a naming convention adopted by the standard.

HTH

Thomas


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