Chris Russell wrote:
Let me first describe my heterogeneous container hack and perhaps you could
point why it's poor (your feel better on a quick read of your paper and this
is a good way to help us all understand this a bit better).

My goal was to be able to use standard STL containers and iterators with
heterogeneous collections of objects. My hack was to declare a class
CMoniker that takes a pointer to some CMonikerBase-derived class through a
templated constructor. This constructor does two things: it casts the
pointer to a void * and stores it in a private member. Additionally it uses
RTTI to record the type. CMonikerBase is invasive; it provides reference
counting for the object and operator overloads for STL containers. Any class
that derives from CMonikerBase can then be stuffed into a CMoniker, and I
then use the standard STL containers/iterators to work with homogenous
collections. A CMoniker has a templated operator: template <typename Type>
operator Type&() that internally uses RTTI to test Type and throw an
exception if it doesn't match the internal type squirreled away in the
constructor. Ugly - yes. The filtering operation you propose in your paper
is similar to little helper classes I write to enumerate elements in my
some_stl_container<CMoniker> to produce another container full of objects of
a given type - again this is inelegant but it does seem to work.
I'm probably wrong, but it looks like boost::any. I can't tell a difference, at least.

- Volodya

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to