On 2015-05-04 17:21:34 +0000, ketmar said:

that's due to `enum` keyword abusing. "enum type" is something like this:

  enum MyEnum { A, B }

and

  enum val = false;

is a compile-time boolean constant, which will be inlined on using. i.e.
compiler will inline such "enum constants", and that constants has the
corresponding type, they aren't enums.

Hmm... Ok, I understand that these seems to be two different things. Not sure if I now understand this correct then:

enum A {a, b, c};

enum members1 = __traits(allMembers, A);
auto members2 = __traits(allMembers, A);

pragma(msg, typeof(members1));
pragma(msg, typeid(members1));

pragma(msg, typeof(members2));
pragma(msg, typeid(members2));



Gives this:

(string, string, string)
playground.d(9): Error: no type for typeid(members1)
playground.d(9):        while evaluating pragma(msg, typeid(members1))

(string, string, string)
playground.d(12): Error: no type for typeid(members2)
playground.d(12):        while evaluating pragma(msg, typeid(members2))



1. So the (string, string, string) output is based on the expression of members1? Meaning, the right-hand-side.

2. I'm wondering why members1 doesn't has a type at all. So, we don't have a compile-time boolean?

3. For members2, where auto is used, I would expect that the return type of "allMembers" is used. Which would be a tuple. But again, no type for members2. Which I find quite strange.



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

Reply via email to