原文 可以這樣:
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);