Get superclasses at compile time
Straivers via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jan 4 20:37:59 PST 2016
Hello,
I'm working on an event system, and I want to be able to check if
an event is a subclass of another event. How might I go about
this? In essence, I'm looking to compress this:
static if (E == UserInputEvent || E == MouseEvent || E ==
MouseButtonEvent || E == MouseReleasedEvent)
{
//MouseEvent => MouseButtonEvent => MouseReleasedEvent
mreListeners[mrePtr] = listener;
mrePtr++;
}
into something like this:
static if (isSuperclassOf!(MouseReleasedEvent, E))
{
mreListeners[mrePtr] = listener;
mrePtr++;
}
Thank you for your time.
-S
More information about the Digitalmars-d-learn
mailing list