Function parameters UDAs
Machine Code
jckj33 at gmail.com
Tue Jun 11 02:04:13 UTC 2019
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.
>
> The following:
> ```
> import std.traits;
>
> struct s { string foo; }
> void foo(@s("aaa") int a, bool x);
>
> void main()
> {
> alias P = Parameters!foo;
> enum udas = __traits(getAttributes, P);
> pragma(msg, udas);
> }
> ```
> will print `tuple(s("aaa"))`
>
> but if you change `foo` to `void foo(int a, @s("aaa") bool x);`
>
> you get `Error: first argument is not a symbol`
>
> Is this a current limitation or I'm using the wrong approach?
I also, quite disappointed how UDAs doesn't work with enums. I
end up using struct + enum to simulate that, sometimes it's quite
a work.
More information about the Digitalmars-d-learn
mailing list