$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Eric Friedman (ebf_at_[hidden])
Date: 2007-09-08 14:22:43
Christian,
On 9/7/07, Christian Holmquist <c.holmquist_at_[hidden]> wrote:
> Is there any visitor mechanism somewhere in boost that allows one to
> introspect the contained type of a boost::any?
> I've been using boost::variant frequently and I love the way its visitor
> works, but it's not always practical to know all possible types at compile
> time (library dependencies, compilation time etc..).
[snip]
> Does anyone else have a use for this, or have another solution at hand?
Some long time back I had added support into Boost.Any for visitation:
http://boost-sandbox.cvs.sourceforge.net/boost-sandbox/boost-sandbox/boost/any.hpp?view=markup
Basically, the interface is as seen in the `test_dynamic_visit` test case:
class my_visitor
: public boost::dynamic_visitor_base,
public boost::dynamic_visitor_interface<T1>,
...,
public boost::dynamic_visitor_interface<TN>
{
...
public:
/*override*/ void visit(T1&);
...
/*override*/ void visit(TN&);
};
and then an instance of the visitor may be passed to a boost::any:
boost::any a = ...;
my_visitor v;
boost::apply_visitor(v, a);
Of course this assumes (parts of) the Boost.Visitor library, also in
the sandbox.
In any case, something based on this idea might be another alternative
to what you're proposing.
Eric