compile time class introspection?

serg why.you.need at my.email
Thu Jun 14 06:27:50 PDT 2007


What really want is, to have a template mixin method that depending on class it inserted into, could call internally a member method if it available.

Something like this:

template dispatchT(T)
{
    void dispatch(int msg)
    {
        switch (msg)
        {
        case WM_CLOSE:
            static if (OnClose in T) // <-- T has desired method
                return OnClose();
            static else
                break;
        case WM_DESTROY:
            static if (T.OnDestroy) // <-- same, but different syntax
                return OnDestroy();
            static else
                break;
        default:
        }
        return DefWndProc();
    }
}

class Window
{
    void OnClose(){}
    void OnDestroy(){}
    mixin dispatchT!(Window);
}


-- serg.


More information about the Digitalmars-d-learn mailing list