On 23.07.2018 19:05, Jean-Louis Leroy wrote:


This works:

   static foreach (fun; __traits(allMembers, genfun)) {
     static if (fun == "foo") {
       static if (is(typeof(__traits(getOverloads, genfun, fun)))) {
         static foreach (ovl; __traits(getOverloads, genfun, fun)) {
           void internal(Parameters!ovl args) {
             mixin(fun)(args);
           }
           mixin("alias %sbar = internal;".format(fun));
         }
       }
     }
   }


Does anyone see a potential problems with this?

It generates additional symbols.

Or a better solution? I would like to avoid the alias.

You can mix in the entire declaration.

mixin(`void `~fun~`bar(Parameters!ovl args) { mixin(fun)(args); }`);

It would of course be useful if the locations where string mixins can occur were less restricted, such that things like

void mixin(fun~`bar`)(Parameters!ovl args){ ... }

would work too, but this will require a DIP.

Reply via email to