Get superclasses at compile time

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jan 4 20:41:45 PST 2016


On 05/01/16 5:37 PM, Straivers wrote:
> 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

is(E : UserInputEvent)


More information about the Digitalmars-d-learn mailing list