On Dec 3, 2005, at 15:44, David Abrahams wrote:
Hugh Hoover
writes: 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
<snip>
Have you looked at boost::indirect_iterator? Just make a container of pointers to the abstract base and iterate over that :)
Thanks for the suggestion, but that won't really work. <snip>
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).
There are sometimes interesting ways to move the boundary between static and dynamic polymorphism around that can solve problems like this one. http://boost-consulting.com/slides/connections05/Life%20On%20the% 20Edge.ppt might be of some use to you.
Thanks - very useful, but I'm not sure it's useful for this problem :) I can't see how to reconcile my requirement for handling classes not known at compile time (in fact, CANNOT be known at compile time due to the dynamically loaded module requirement) with meta-programming. While I'd PREFER a meta-programming approach for performance and simplicity - I'm just not grokking an approach here other than the use of virtual functions. The notion introduced in the "loans" example of separating iteration by type may help, and I'll need to think on that more - perhaps pushing the iteration itself into the class-dependent code. In the meantime - I wrote a template that makes creating the iterators (and assistant) in the abstract interface easier ;^) Hugh Hoover Enumclaw Software