How to get the UDAs for a function parameter correctly?
Adam D. Ruppe
destructionator at gmail.com
Mon May 11 02:34:32 UTC 2020
On Monday, 11 May 2020 at 02:25:39 UTC, Heromyth wrote:
> I want to get the UDAs for for a function parameter. Here the
> test code and I got some errors:
I think my blog aside is one of the few if only write-ups on how
to do this:
http://dpldocs.info/this-week-in-d/Blog.Posted_2019_02_11.html#how-to-get-uda-on-a-function-param
the library will not help much, you need to slice the parameters
yourself. (It might work combine lib stuff with slice though,
e.g. getUDA!(Parameters!F[1 .. 2]) maybe, i have never tried).
but this does work:
static if(is(typeof(method) P == __parameters))
foreach(idx, _; P) {{
// alias for convenience later
alias param = P[idx .. idx + 1]; // this slice is
the trick
// can get the identifier now
string ident = __traits(identifier, param);
// and the attributes
foreach(attr; __traits(getAttributes, param))
{}
}}
More information about the Digitalmars-d-learn
mailing list