CTFE & enums & static assert

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon May 4 10:21:34 PDT 2015


On Mon, 04 May 2015 18:21:59 +0200, Robert M. Münch wrote:

> I find this a bit strange:
> 
> // get all rules that start with p...
> enum BolRules = StaticFilter!(beginsWithP,
> __traits(allMembers,BolSource));
> static assert(is(BolRules == enum));
> 
> Compiling using dmd...
> source/app.d(114): Error: static assert  (is(BolRules == enum)) is false
> 
> I'm trying to construct an enum that can be used in a "final switch" to
> check if all cases were handled. But so far it's not working, because I
> can't get the enum constructed.

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.
-------------- 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/30f25079/attachment.sig>


More information about the Digitalmars-d-learn mailing list