views:

189

answers:

3

I have been searching for sample code creating iterator for my own container, but I haven't really found a good example. I know this been asked before (http://stackoverflow.com/questions/148540/c-creating-my-own-iterators) but didn't see any satisfactory answer with examples.

I am looking for simple sample code to start how to design my own iterator.

Thanks

+5  A: 

Here you could find good intro for creating custom iterators. Also take a look on the Boost.Iterator Library.

Kirill V. Lyadvinsky
More specifically, the iterator_adaptor is a thing of beauty. With only a few lines of code you end up with a full-blown iterator.
Matthieu M.
`iterator_facade` is very helpful too
jalf
+1  A: 

I found Matthew Wilson's 'extended STL' very educative on the subject. Contains lots of do's and don'ts, plus tons of practical programming tips. I think this guy really knows what he's doing. (created libraries for that, too)

xtofl
A: 

Nicolai Josuttis has an example of a user defined iterator in his book: C++ Standard Library, a tutorial and a reference.

Here is the example online:

http://www.josuttis.com/libbook/iter/assoiter.hpp http://www.josuttis.com/libbook/iter/assoiter.cpp

navigator