Hello Marcel!
You raise a very interesting question (for which I don't
have a clean answer).
Without going into why you might want to do this or
whether it would be a good idea, I do think you raise
a very interesting general point.
In the "old days" you might do something like:
typedef struct Element { Element* pElement; } element_type;
typedef element_type collection_type[30];
This is a very standard usage, purposely supported
by the language, and used, e.g., by the classic linked
list.
This works because you can use pointers to incomplete
types. (You can also forward-declare incomplete types.)
Now one aspect of iterators is that they are abstractions
or generalizations of pointers. So you raise the very
natural question of how or whether the same thing might
be done with iterators.
As far as I know, you can't, but I would love to be
shown wrong.
Of course, "All problems can be solved by another level
of indirection." So you could do something like:
#include <map>
using std::multimap;
struct iterator_wrapper;
typedef int key_type;
typedef iterator_wrapper* element_type;
typedef multimap<key_type, element_type> map_type;
typedef map_type::iterator iterator_type;
struct iterator_wrapper { iterator_type it; };
This, to my mind, has two imperfections: Iterators are
already a form of indirection, so the extra level of
indirection -- element_type is a pointer -- seems
conceptually unnecessary, and could add a little cost.
Also, while adding no run-time cost, the need to wrap
the iterator in iterator_wrapper (I don't see any way
to avoid this.) seems unfortunate.
Your desired use case illustrates a feature of pointers
that iterators do NOT provide. Would it make sense for
the language / standard library to provide such functionality
for iterators? (And would it be possible, given that
standard-library collections are templates?)
> Marcel
Best regards.
K. Frank