How to iterate getSymbolsByUDA

Eko Wahyudin eko.wahyudin at yahoo.co.id
Sat Nov 24 03:48:12 UTC 2018


Hi all,
anyone know how to iterate getSymbolsByUDA ?

I try this code:

enum Attr;
struct A
{
     @Attr int a;
     int b;
}

//-------------------------------------------
//1. Error: need `this` for `a` of type `int`
foreach(sym; getSymbolsByUDA!(A, Attr)){
	writeln(sym.stringof);	
}


for(sizediff_t i=0; i<getSymbolsByUDA!(A, Attr).length; i++){

         //-----------------------------------------------------
         //2. error: variable `i` cannot be read at compile time
         writeln(getSymbolsByUDA!(A, Attr)[i].stringof);
	
}

//-----------------------------------------------------
//3. this OK, but the index is a constant, i don't like it.
writeln(getSymbolsByUDA!(A, Attr)[0].stringof);


Thankyou before


More information about the Digitalmars-d-learn mailing list