d简化导入
原文
可以这样:
struct MY_KEY
{
template opDispatch(string name)
{
static import bindbc.glfw;
mixin(`alias opDispatch = bindbc.glfw.GLFW_KEY_`, name, `;`);
}
}
这样,写MY_KEY.FOO就是写GLFW_KEY_FOO.
同样,消除手动混杂C接口:
auto opDispatch(string func, Args...)(Args args) {
enum expr = format!q{
return pl_%s(plotter, args);
}(func);
mixin(expr);
}
这样,不用:
pl_flinewidth_r(plotter, 1);
而只需要:
plotter.flinewidth_r(1);
浙公网安备 33010602011771号