digitalmars.D.learn - convertion of type tuple to enum
- drug (30/30) Nov 24 2015 What is the best way to do subj? I did
What is the best way to do subj? I did ``` import std.array: array; import std.typetuple: TypeTuple; import std.typecons: tuple; import std.traits: EnumMembers; struct Foo {} struct Bar {} struct FooBar {} struct Baz {} string convertTypeTupleToEnum(Types...)() { string s = "enum Kind { "; foreach(T; Types) { s ~= T.stringof ~ ", "; } s ~= "}"; return s; } alias Types = TypeTuple!(Foo, Bar, FooBar, Baz); void main() { mixin(convertTypeTupleToEnum!(Types)); assert(EnumMembers!Kind.tuple.array == [ Kind.Foo, Kind.Bar, Kind.FooBar, Kind.Baz]); } ``` (also here http://dpaste.dzfl.pl/bc6f19770f85). Is there a way to do it without string mixin? Thanks!
Nov 24 2015