how can i use the derive-hierarchy at runtime for typechecking?

Chris Nicholson-Sauls ibisbasenji at gmail.com
Thu Sep 20 16:57:06 PDT 2007


Jarrett Billingsley wrote:
> "Chris Nicholson-Sauls" <ibisbasenji at gmail.com> wrote in message 
> news:fcupko$kh7$2 at digitalmars.com...
> 
>> void ifIs (S, T) (S obj, void delegate(T) dg) {
>>   if (auto casted = cast(T) obj) dg(casted);
>> }
> 
> Or you could skip Downs' confusing way of writing code entirely ( ;) ) and 
> just use:
> 
> if(auto b = cast(B)foo)
> {
>     // do stuff with b
> } 
> 
> 

Or we could add a new '?.' form for member access that becomes a nop on null references 
and just use:
(cast(B) foo)?.doStuff();

Er.......... okay, that's just insane.

-- Chris Nicholson-Sauls


More information about the Digitalmars-d-learn mailing list