How to implement an STL-style iterator and avoid common pitfalls?

I made a collection for which I want to provide an STL-style, random-access iterator. I was searching around for an example implementation of an iterator but I didn’t find any. I know about the need for const overloads of [] and * operators. What are the requirements for an iterator to be “STL-style” and what are some other pitfalls to avoid (if any)?

Additional context: This is for a library and I don’t want to introduce any dependency on it unless I really need to. I write my own collection to be able to provide binary compatibility between C++03 and C++11 with the same compiler (so no STL which would probably break).

8 Answers
8

Leave a Comment