Boost logo

Boost :

From: Neal D. Becker (nbecker_at_[hidden])
Date: 2004-11-10 14:01:22


I was struggling with const correctness and iterator adaptors. At first I was
using iterator_facade. I found it difficult to get dereference to work
correctly. After changing to iterator_adaptor I got things working. I'm
wondering if the approach I used is "correct".

I include the whole class here, because it isn't really very big.

I was using a Ring class which contains an iterator, which is
cycle_iterator<std::vector<Complex>::iterator>.

If a Ring const& is passed I had problems with dereference.

The changes I made to cycle_iterator fix this were:

1) Add templated conversion constructor to cycle_iterator, to allow implicit
conversion of cycle_iterator -> const cycle_iterator.

2) Include both

reference dereference()

and

const reference dereference() const

(likewise for operator[])

So, do my changes constitute a "correct" approach to making interoperable
iterators using boost::iterator_adaptor?




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