Re: lazy evaluation of logical operators in enum definition

2018-04-18 Thread Meta via Digitalmars-d
On Wednesday, 18 April 2018 at 10:19:20 UTC, Atila Neves wrote: On Wednesday, 18 April 2018 at 04:44:23 UTC, Shachar Shemesh wrote: On 17/04/18 13:59, Simen Kjærås wrote: [...] Also, extremely dangerous. Seriously, guys and gals. __traits(compiles) (and its uglier sibling, is(typeof()))

Re: lazy evaluation of logical operators in enum definition

2018-04-18 Thread Timon Gehr via Digitalmars-d
On 18.04.2018 09:18, Walter Bright wrote: On 4/15/2018 10:57 PM, Shachar Shemesh wrote: It seems that the && evaluation does not stop when the first false is found. Evaluation does stop, semantic analysis does not. For example:   bool foo() {     return 0 && undefined_variable;   } does

Re: lazy evaluation of logical operators in enum definition

2018-04-18 Thread Atila Neves via Digitalmars-d
On Wednesday, 18 April 2018 at 04:44:23 UTC, Shachar Shemesh wrote: On 17/04/18 13:59, Simen Kjærås wrote: [...] Also, extremely dangerous. Seriously, guys and gals. __traits(compiles) (and its uglier sibling, is(typeof())) should be used *extremely* sparingly. [...] A very good rule of

Re: lazy evaluation of logical operators in enum definition

2018-04-18 Thread Walter Bright via Digitalmars-d
On 4/15/2018 10:57 PM, Shachar Shemesh wrote: It seems that the && evaluation does not stop when the first false is found. Evaluation does stop, semantic analysis does not. For example: bool foo() { return 0 && undefined_variable; } does not compile. I'd speculate that most would

Re: lazy evaluation of logical operators in enum definition

2018-04-17 Thread Shachar Shemesh via Digitalmars-d
On 17/04/18 13:59, Simen Kjærås wrote: There's a kinda neat (and kinda ugly) way to implement prop in one line:     enum prop(T) = __traits(compiles, { static assert(T.member == 3); }); Now, that's not the same as short-circuiting, and only useful in some cases, but for those cases, it's

Re: lazy evaluation of logical operators in enum definition

2018-04-17 Thread Simen Kjærås via Digitalmars-d
On Monday, 16 April 2018 at 05:57:01 UTC, Shachar Shemesh wrote: Consider the following program: struct S1 { enum member = 3; } struct S2 { enum member = 2; } struct S3 { } enum prop(T) = __traits(hasMember, T, "member") && T.member==3; pragma(msg, prop!S1); pragma(msg, prop!S2);

Re: lazy evaluation of logical operators in enum definition

2018-04-17 Thread Jacob Carlborg via Digitalmars-d
On Monday, 16 April 2018 at 05:57:01 UTC, Shachar Shemesh wrote: Consider the following program: struct S1 { enum member = 3; } struct S2 { enum member = 2; } struct S3 { } enum prop(T) = __traits(hasMember, T, "member") && T.member==3; pragma(msg, prop!S1); pragma(msg, prop!S2);

Re: lazy evaluation of logical operators in enum definition

2018-04-16 Thread Basile B. via Digitalmars-d
On Monday, 16 April 2018 at 05:57:01 UTC, Shachar Shemesh wrote: Consider the following program: struct S1 { enum member = 3; } struct S2 { enum member = 2; } struct S3 { } enum prop(T) = __traits(hasMember, T, "member") && T.member==3; pragma(msg, prop!S1); pragma(msg, prop!S2);