InstanceOf

Lemonfiend lemon at fie.nd
Sun Jun 23 04:26:32 PDT 2013


> foreach (I i; array) {
>     if (B b = cast(B) i) { ... }
> }

Thanks all 3 of you for the quick and identical answers. :)

It had not occurred to me to use a cast for this, but indeed the 
language ref says the same:
"In order to determine if an object o is an instance of a class B 
use a cast"

It does a bit inelegant to me.. Or are casts simply extremely 
cheap?




More information about the Digitalmars-d-learn mailing list