[type_erasure] any_cast to a base class?
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
AMDG On 03/12/2014 04:22 AM, Phil Endecott wrote:
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
(&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?
There is some possible magic involving dynamic_cast internally, but it's a bit unreliable. I decided that it wasn't worth it for Boost.TypeErasure. (Look up Boost.DynamicAny, which Alexander Nasonov proposed a while back.)
(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.)
These are completely unrelated types.
I don't see how I could make it work in general.
I suppose that it would be possible with some help:
convertible_to
participants (2)
-
Phil Endecott
-
Steven Watanabe