instanceof?
Adam D. Ruppe
destructionator at gmail.com
Wed Aug 1 19:02:41 PDT 2012
On Thursday, 2 August 2012 at 01:59:02 UTC, Maxime Chevalier
wrote:
> These both seem a little clumsy, however. Is there a better way
> to do this?
I don't know if it is the best way, but I use the cast myself,
though I like using a little wrapper:
T instanceof(T)(Object o) if(is(T == class)) {
return cast(T) o;
}
Then, you can say
if(object.instanceof!SomeClass) {
// use
}
or
if(auto some_class = object.instanceof!SomeClass) {
// use some_class
}
More information about the Digitalmars-d-learn
mailing list