Another simple example that have helped me tremendously when debugging OpenGL calls. A simple dispatcher that checks glGetError after every call.

struct GL
{
    auto opDispatch(string name, Args...)(Args args)
    {
        enum glName = "gl" ~ name;
        mixin(format("
        static if(is(ReturnType!%1$s == void))
        {
            %1$s(args);
            checkGLError();
        }
        else
        {
            auto r = %1$s(args);
            checkGLError();
            return r;
         }", glName));

    }
}
GL gl;

I simply use gl.funcName instead of glFuncName. opDispatch rules!.

Reply via email to