can I generate an enum from a typelist?

Frustrated Who at where.com
Tue Apr 8 05:39:20 PDT 2014


On Tuesday, 8 April 2014 at 08:31:16 UTC, Vlad Levenfeld wrote:
> Ok, starting to feel a bit sheepish at this point, that 
> constructor was unnecessarily verbose:
>
> this (T) (T layer)
> {
> 	import std.string: toLower;
> 	mixin ("this."~toLower (T.stringof)~"= layer;");
> 	this.type = cast (const) typeid (T);
> }
>
> ...is what I have settled on.
> Sorry for all the noise! There doesn't seem to be a way to edit 
> posts here...

You can simply reflect on your nested structs and generate the 
enum from them. No need to duplicate anything.

The only thing you have to do is figure out how to determine if a 
nested struct is part of the enum. If all nested structs of Layer 
are then it is easy. Else some naming scheme or inheritance needs 
to be used to distinguish them from others.



More information about the Digitalmars-d-learn mailing list