[suggestion] importing and renaming by wildcard and/or regexp

Ali Çehreli acehreli at yahoo.com
Thu Aug 11 05:25:34 UTC 2022


On 7/27/22 06:41, Paul Backus wrote:

 > ```d
 > struct MY_KEY
 > {
 >      template opDispatch(string name)
 >      {
 >          static import bindbc.glfw;
 >          mixin(`alias opDispatch = bindbc.glfw.GLFW_KEY_`, name, `;`);
 >      }
 > }
 > ```
 >
 > This will let you write `MY_KEY.FOO` and get an alias for `GLFW_KEY_FOO`.

Yep! :) I experimented with the same method to erase manual name 
mangling of C APIs:

   auto opDispatch(string func, Args...)(Args args) {
     enum expr = format!q{
       return pl_%s(plotter, args);
     }(func);

     mixin(expr);
   }

Note: Yes, my use of format is likely unnecessarily slow.

For example, instead of the C style

   pl_flinewidth_r(plotter, 1);

I wrapped the pointer in a struct and could be more D-like:

   plotter.flinewidth_r(1);

Ali



More information about the Digitalmars-d mailing list