How to iterate getSymbolsByUDA

Eko Wahyudin eko.wahyudin at yahoo.co.id
Sat Nov 24 08:50:59 UTC 2018


On Saturday, 24 November 2018 at 08:09:38 UTC, Stanislav Blinov 
wrote:
> On Saturday, 24 November 2018 at 03:48:12 UTC, Eko Wahyudin 
> wrote:
>> Hi all,
>> anyone know how to iterate getSymbolsByUDA ?
>
> enum Attr;
> struct A
> {
>     @Attr int a;
>     int b;
>
>     @Attr void foo() {}
>     @Attr void foo(int) {}
> }
>
> void main() {
>     import std.traits;
>     import std.stdio;
>
>     alias symbols = getSymbolsByUDA!(A, Attr);
>
>     A a;
>
>     static foreach (i; 0 .. symbols.length) {
>         writeln("identifier: ", __traits(identifier, 
> symbols[i]));
>         static if (is(typeof(symbols[i]) == int)) {
>             __traits(getMember, a, __traits(identifier, 
> symbols[i])) = 42;
>         }
>     }
>
>     assert(a.a == 42);
> }

aah ya,, this statement is work

static foreach (i; 0 .. symbols.length)

thank you.


More information about the Digitalmars-d-learn mailing list