From: Corwin Joy (cjoy_at_[hidden])
Date: 2001-08-07 02:06:33
----- Original Message -----
From: "Dave Vasilevsky" <gridd_at_[hidden]>
Sent: Tuesday, August 07, 2001 12:01 AM
Subject: [boost] Visiting boost::any
> I've been trying to use boost::any in one of my projects, but I keep
> against a problem: Templates and boost::any don't work together the way
> like them to.
> But this doesn't work either, since virtual methods can't be templated. So
> question: is there a way to implement the visitor idiom with any, or a
> modified version thereof? Using just virtual methods, one could easily
> implement a push_back() operation for any; but a new method must be added
> the definition of any every time one wants to add another operation. Is
> general solution?
There are only a few solutions I know of. One is to simply register
functions outside the any class and use RTTI hooks exposed by any. You can
see this in a beta I posted to the Yahoo boost group called any_ccast to do
conversion casts. The other is to use a callback type framework... but
there you do have to customize the class somewhat... I wrote a short little
paper on this at http://www.geocities.com/corwinjoy/vo/VariantObject.htm.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk