Discussion Thread: DIP 1030--Named Arguments--Final Review

Paul Backus snarwin at gmail.com
Thu May 21 15:25:21 UTC 2020


On Thursday, 21 May 2020 at 01:07:36 UTC, Paul Backus wrote:
> It's pretty ugly, but the ugliness is hidden entirely inside 
> the function's implementation. And the whole static if block 
> could be factored out into a mixin if you wanted to re-use it 
> in multiple functions.

To wit:

mixin template parameterAliases(names...)
{
     static if (is(typeof(__traits(parent, {})) params == 
__parameters))
         static foreach (i, name; names)
             mixin("alias ", name, " = ", __traits(identifier, 
params[i..i+1]), ";");
}

int foo(int, int)
{
     mixin parameterAliases!("x", "y");
     return x + y;
}


More information about the Digitalmars-d mailing list