From: Hugh Hoover (hugh_at_[hidden])
Date: 2005-12-03 17:21:52


I have a need to provide STL compliant iterators from an abstract
class A, that is, without knowing the runtime type of the actual
"collection" being iterated.. As near as I can tell, these things
don't mix well. My best so far is to create an abstract
"iterator_assister" which provides dereference, (in|de)crement and
is_equal, and use a boost::iterator_adaptor derived class to provide
the iterator the client code uses, and allocate the iterator_assister
derived class from the implementation class (derived from A) that's
being iterated over.

This solution has obvious downsides. I can't imagine that this is a
unique problem. Certainly, people significantly smarter than me have
figured out a good solution to this? In my reading and browsing,
though, I've never seen the problem presented, never mind solved. In
my early C++ days, we used allocated iterators rather than the
current STL style.

Can anyone provide pointers to what I SHOULD be reading for a good
solution?

I believe I NEED to use abstract classes here rather than meta-
programming with known types at runtime - the client code will need
to iterate over classes loaded from dynamic libraries that are not
known to the client code (except by abstract interface).

Thanks

Hugh Hoover
Enumclaw Software