Boost logo

Boost :

Subject: Re: [boost] [type_erasure] Downcasting is now possible
From: Matt Calabrese (rivorus_at_[hidden])
Date: 2015-03-09 17:04:50

On Sat, Mar 7, 2015 at 8:27 PM, Steven Watanabe <watanabesj_at_[hidden]>

> The calls to register_binding are necessary for
> this to work, unfortunately. I don't think it's
> possible to implement dynamic_any_cast without
> some kind of registration, but at least it only
> needs to be called once for each concept/type
> combination. If anyone has any better ideas
> about how to handle this, I'd love to hear it.
> Comments, questions, and criticism are welcome.

Awesome. I haven't looked at the implementation and haven't thought about
the problem enough, so forgive me if this is a silly question -- why is it
that register_binding needs to be invoked *manually*? In other words, why
can't the instantiation of dynamic_any_cast do something like examine the
types of all of the concepts involved, then force an instantiation of a
template for each of those concept types, which would perform the
registration? To be clear, the purpose of this instantiation would be to
create a type that has a static member with a constructor that performs the
registration. You'd just need to then "touch" the object to make sure the
constructor actually gets run. Since the registration is done via an
instantiation of a template that uses the concept as an argument, that
registration is guaranteed to only happen exactly once per concept,
regardless of how many times the dynamic_any_cast is used across
translation units.

-Matt Calabrese

Boost list run by bdawes at, gregod at, cpdaniel at, john at