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);
posted @ 2022-08-11 15:42  zjh6  阅读(18)  评论(0)    收藏  举报  来源