CTFE & enums & static assert

2015-05-04 Thread Robert M. Münch via Digitalmars-d-learn
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 constru

Re: CTFE & enums & static assert

2015-05-04 Thread ketmar via Digitalmars-d-learn
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)

Re: CTFE & enums & static assert

2015-05-04 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-05-04 17:21:34 +, 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 co

Re: CTFE & enums & static assert

2015-05-04 Thread Ali Çehreli via Digitalmars-d-learn
On 05/04/2015 11:07 AM, Robert M. Münch wrote: > enum A {a, b, c}; > > enum members1 = __traits(allMembers, A); > auto members2 = __traits(allMembers, A); > > 1. So the (string, string, string) output is based on the expression of > members1? Meaning, the right-hand-side. There are many differe

Re: CTFE & enums & static assert

2015-05-04 Thread ketmar via Digitalmars-d-learn
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.

Re: CTFE & enums & static assert

2015-05-05 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-05-04 22:22:51 +, ketmar said: 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. No, that makes it much more clearer for me. The compiler should

Re: CTFE & enums & static assert

2015-05-15 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-05-04 18:22:17 +, 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 t

Re: CTFE & enums & static assert

2015-05-15 Thread Ali Çehreli via Digitalmars-d-learn
On 05/15/2015 09:45 AM, Robert M. Münch wrote: > On 2015-05-04 18:22:17 +, Ali Çehreli said: >> TypeTuple is great because it enables "compile-time foreach" >> (unfortunately, implicitly): >> >> foreach (m; __traits(allMembers, A)) { >> // This body is repeated for each member

Re: CTFE & enums & static assert

2015-05-18 Thread Robert M. Münch via Digitalmars-d-learn
On 2015-05-15 17:26:50 +, Ali Çehreli said: On 05/15/2015 09:45 AM, Robert M. Münch wrote: > 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) ... Sorry, I don't understand your question. :( Do y