It's possible to declare a variable inside a static foreach()?

Marc jckj33 at gmail.com
Thu Dec 21 16:25:00 UTC 2017


For example, I'd like to declare a variable inside a static 
foreach like in below code, just for better organization, 
otherwise, I have to use the value directly instead of the 
variable. If the value is used more than once, it might be 
inviable.

>	enum allMembers = __traits(derivedMembers, C);
>	static foreach(enum string member; allMembers) {		
>		enum attributes = __traits(getAttributes, __traits(getMember, 
>C, member));
>		static foreach(C c; attributes) {
>			writeln(c);
>		}
>	}

I got redefinition erros of "atributes" on this. Can I have this 
only at compile time?


More information about the Digitalmars-d-learn mailing list