How to correctly implement custom iterators and const_iterators?

I have a custom container class for which I’d like to write the iterator and const_iterator classes.

I never did this before and I failed to find an appropriate how-to. What are the guidelines regarding iterator creation, and what should I be aware of ?

I’d also like to avoid code duplication (I feel that const_iterator and iterator share many things; should one subclass the other ?).

Foot note: I’m pretty sure Boost has something to ease this but I can’t use it here, for many stupid reasons.

9 Answers
9

Leave a Comment