rtti cast

terranium spam at here.lot
Wed May 7 05:10:39 PDT 2008


Jarrett Billingsley Wrote:

> I perform downcasts extremely rarely.
That's *exactly* why you need safe cast.

> 
> if(auto y = cast(Y)x)
>     ...
> else
>     // not a Y, try something else
yeah, try something else, hide the bug :)

> Furthermore, it's a lot easier and more efficient to have the cast return 
> null and throw an exception _only if needed_ than to throw an exception and 
> then have to catch it:

most programmers won't bother to thow an exception in this case, they just cast and go.

> For that matter, some languages (like C#) have both kinds of casts - one 
> that throws an exception and one that doesn't.  Either can really be 
> implemented in the other, but the null-returning kind is more basic and 
> efficient. 
...efficient bugmaker.



More information about the Digitalmars-d mailing list