January 23, 2014
On Thursday, 23 January 2014 at 17:59:05 UTC, Uplink_Coder wrote:

First and foremost, I'd suggest you use the beautiful solution proposed by Meta.

But to illustrate problems with your code:

>   foreach (i,Item;[__traits(allMembers,Enum)]) {

This is the culprit. More specifically, you don't need to put the result of __traits into array. __traits(allMembers) returns a tuple which can be iterated at compile time. This is how it would look:

auto EnumToSelect(Enum)(string Name = __traits(identifier,Enum)) if (is(Enum==enum)) {
	string form_string;
        // Note, there are no [] enclosing __traits
	foreach (i,Item;__traits(allMembers,Enum)) {
		form_string ~=
			"\toption(value='"~Item~"') "
			~__traits(getMember,Enum,Item)~"\n";
	}
	return form_string;
}
January 23, 2014
Great now it works!

Thanks for your time :D
1 2
Next ›   Last »