Re: Getting Field Names of a specific UDA in compile time.

2020-10-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 10/3/20 10:16 AM, realhet wrote: I tried it to put into a function: auto getSymbolNamesByUDA(T, string uda)(){     string[] res;     static foreach(a; getSymbolsByUDA!(T, uda)) res ~= a.stringof;     return res; } D __traits give you strings, the std.traits thing is giving you symbols.

Re: Getting Field Names of a specific UDA in compile time.

2020-10-03 Thread realhet via Digitalmars-d-learn
On Saturday, 3 October 2020 at 14:00:30 UTC, Adam D. Ruppe wrote: On Saturday, 3 October 2020 at 13:10:31 UTC, realhet wrote: I only managed to get the string[] by making a static foreach, but I don't know how to put that in an enum xxx = ...; statement. There's always other ways but general

Re: Getting Field Names of a specific UDA in compile time.

2020-10-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Saturday, 3 October 2020 at 13:10:31 UTC, realhet wrote: I only managed to get the string[] by making a static foreach, but I don't know how to put that in an enum xxx = ...; statement. There's always other ways but general rule: if you can get it one way, just wrap that up in a function

Getting Field Names of a specific UDA in compile time.

2020-10-03 Thread realhet via Digitalmars-d-learn
Hi, class Printer{ @("NODES") int gem1, gem2, gem3, gem4, gem5, head1, head2, head3, head4; import std.traits, std.meta; alias Nodes = getSymbolsByUDA!(typeof(this), "NODES"); enum NodeNames = ["gem1", "gem2", ]; } Is there a way to make an enum like the above with compile time