Questions on the new __traits(parameters)

Adam D Ruppe destructionator at gmail.com
Thu Mar 10 12:27:33 UTC 2022


On Thursday, 10 March 2022 at 10:18:09 UTC, Quirin Schroll wrote:
> The issue is not the complexity of the workaround (example 
> below), but that it is in practice hard to know when it applies 
> and it is *hard to teach*


__traits(parameters) always gives the parameters of the function 
in which it is used *even if it is used inside a nested function*.

> ### Workaround
> Say you wanted to access the function's parameters in a 
> `foreach` loop. Say you are in a meta-programming context where 
> you don't know the type of the range.
> ```D
> void f(R, Ts...)(R range, int param, Ts args)
> {
>     foreach (auto ref x; range)
>     {
>         // some amount of code
>         g!(Ts[1..$])(x, __traits(parameters)[1..$]);

Why wouldn't you just use `args` here? The __traits(parameters) 
actually doesn't give any real value when you already have a 
variadic.


More information about the Digitalmars-d mailing list