Function parameters UDAs

Adam D. Ruppe destructionator at gmail.com
Wed Nov 14 18:05:55 UTC 2018


On Wednesday, 14 November 2018 at 16:28:19 UTC, Radu wrote:
> Looks like that there is no easy way to extract a function 
> parameters UDA list.

Indeed, the only way I can find is kinda crazy:

---
void foo(int f, @("test") string s) {}

void main() {
         static if(is(typeof(foo) Params == __parameters))
                 pragma(msg, __traits(getAttributes, 
Params[1..2])); // get the second param
}
---


So, the process is:

1) alias the params with the static if + is() statement (this is 
what std.traits.Parameters does internally)

2) slice the params! using params[0] will not work, but params[0 
.. 1] will.

3) get the attributes using the language function


More information about the Digitalmars-d-learn mailing list