Solution 1:

Here are some articles you might find of interest

Giving STL Iterators a Base Class

Type Erasure for C++ Iterators

any_iterator Class Reference

Solution 2:

Better late than never...

The latest issue of C-Vu turned up and guess what was in it: That's right, iterators that do exactly what you wanted.

Unfortunately you need to become a member of the ACCU to view the magazine (the article references the Overload article from 2000 that David links to). But for a measly price a year you get a nice magazine to read, conferences and user groups. When you become a member you can view PDF's of the back issues so what are you waiting for?

Solution 3:

A case of being careful what you ask for. The any_iterator classes you see work on an unbounded set of iterator types. You only have three, which you know up front. Sure, you might need to add a fourth type in the future, but so what if that takes O(1) extra lines of code ?

The big advantage of a closed set of possible contained types is that you have an upper bound on sizeof(), which means you can avoid the heap and the indirection it brings. Basically, stuff them all in a boost::variant and call apply_visitor.