Boost logo

Boost :

Subject: [boost] [type_erasure] any_cast to a base class?
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2014-03-12 07:22:47


Dear Experts,

Can boost::type_erasure::any_cast cast to a base class? For example:

class Base {};
class Derived: public Base {};
Derived d;
any< ??? > a (d);
Base* b = any_cast<Base*>(&a);
assert(b);

I know that this isn't possible with Boost.Any, but was hoping that
Boost.TypeErasure would include some "magic" to make it possible.
Failing that, are there any other options?

(What I'd really like to do is to store a weak_ptr<Derived> and
retrieve a shared_ptr<Base>, and other similar combinations, but
I get stuck before I get that far.)

Thanks, Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk