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);
}