Boost logo

Boost :

Subject: Re: [boost] [type_erasure] Downcasting is now possible
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2015-03-10 13:24:33


On 10/03/2015 17:38, Steven Watanabe wrote:
> AMDG
>
> On 03/10/2015 07:33 AM, Mathias Gaunard wrote:
>> On 08/03/2015 05:27, Steven Watanabe wrote:
>>
>>> 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.
>>
>> If you're doing this, you might as well implement full dynamic duck typing.
>> If the expression is valid, you call it, otherwise you raise an exception.
>>
>
> Oh, I agree. However, the cost of such a call
> is significantly greater then a normal virtual
> call. Thus, I don't want the library to do
> this without being told explicitly that it's the
> desired behavior. With what I have already, the
> implementation of such a feature is trivial. The
> real issue is defining the interface for it.

How about something like this:

any a;
duck_visit(f, a);

with 'f' a polymorphic function object constrained with SFINAE.

if f(a) is callable for the dynamic type of a, then call it, otherwise
raise an exception.


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