convertion of type tuple to enum
drug via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Nov 24 23:49:13 PST 2015
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!
More information about the Digitalmars-d-learn
mailing list