Is it possible to handle 'magic' property assignments a'la PHP?
TheFlyingFiddle
kurtyan at student.chalmers.se
Sun Jan 5 06:36:14 PST 2014
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!.
More information about the Digitalmars-d-learn
mailing list