CTFE & enums & static assert

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 4 15:22:51 PDT 2015


On Mon, 04 May 2015 20:07:27 +0200, Robert M. Münch wrote:

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

`typeid` is runtime thing, you can't use it in compile-time.

besides, as Ali said, `allMembers` returns tuple, which is very special 
thing that exists only in compile-time.

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

that's three field names for `enum A`. and field name is a string.

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

it's a tuple. actually, `(string, string, string)` is a special type.

> 3. For members2, where auto is used, I would expect that the return type
> of "allMembers" is used.

it is. ;-)

> Which would be a tuple. But again, no type for
> members2. Which I find quite strange.

as i said, `typeid` is runtime feature, so you can't print it with pragma. 
and tuples aren't exist in runtime, it's compile-time only.


i think you are even more confused now. ;-) sorry.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150504/5682293b/attachment.sig>


More information about the Digitalmars-d-learn mailing list