static foreach and function generation
Timon Gehr
timon.gehr at gmx.ch
Mon Jul 23 19:21:36 UTC 2018
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.
More information about the Digitalmars-d
mailing list