Boost logo

Boost :

From: Unai Uribarri Rodríguez (unaiur_at_[hidden])
Date: 2003-01-22 15:46:32


Douglas Paul Gregor wrote:
> On Wed, 22 Jan 2003, [ISO-8859-1] Unai Uribarri Rodr?guez wrote:
>
>
>>I propose to implement any_cast<A&>(x) and any_cast<A*>(x) with the
>>semantics of dynamic_cast. That is, if x has type A, any_cast<A&>(x)
>>returns a reference to the content of x and any_cast<A*>(x) returns a
>>pointer to the content of x. Else, any_cast<A&>(x) throws bad_any_cast
>>and any_cast<A*>(x) returns the NULL pointer.
>
>
> I'm assuming you meant any_cast<A*>(&x) and not any_cast<A*>(x).

Yes, it was a mistake.

>
>>any_cast<A>(X) will work the semantics of static_cast, that is, returns
>>a copy of the content of x.
>
>
> Any particular reason why any_cast<A>(x) should return a copy and not a
> reference?

Because any_cast<A&>(x) states more clearly your intention of retrieving
a reference.

I think that there are two reasonable options:
* any_cast<A>(x) could return a copy of the content of x, or
* any_cast<A>(x) could be illegal, as is dynamic_cast<A>(x).


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