On 2015-05-04 18:22:17 +0000, Ali Çehreli said:

There are many different kinds of tuples in D, only two of which I can handle:

1) Tuple from std.typecons, which are ordinarily created at run time

2) TypeTuple from std.typetuple, which are compile-time entities

The documentation is not clear that __traits(allMembers) returns a TypeTuple, which additionally has a bad name.

TypeTuple is great because it enables "compile-time foreach" (unfortunately, implicitly):

     foreach (m; __traits(allMembers, A)) {
         // This body is repeated for each member at compile time
     }

Is there a way I can build an ENUM from within the FOREACH? What I want to achive is, that I would like to use:

final switch (myEnum) ...

and have myEnum build at compiletime. With this the compiler would give an error whenever I have forgotten to update my code to handle a new case.

 > 2. I'm wondering why members1 doesn't has a type at all.

Because it is a TypeTuple of values of various types and even types themselves.

But shouldn't be the type than be "TypeTuple"?

--
Robert M. Münch
http://www.saphirion.com
smarter | better | faster

Reply via email to