www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - New thing I learned for the day

reply Steven Schveighoffer <schveiguy gmail.com> writes:
Did you know this was valid syntax? I didn't.

static if(cond)
    ...
else: // wat...


seen here:
https://github.com/dlang/phobos/blob/3bfccf4f160a07165682549407eaeec5c8907c82/std/utf.d#L4213-L4215

Only seems to work outside of functions, and naturally then not for 
normal if statements.

-Steve
Nov 26 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 26 November 2019 at 15:28:38 UTC, Steven 
Schveighoffer wrote:
 Did you know this was valid syntax? I didn't.
I did not know already, but it is no surprise to me either because the colon works on almost every other attribute like that too... static if and version are similar according to teh grammar.
Nov 26 2019
parent reply Steven Schveighoffer <schveiguy gmail.com> writes:
On 11/26/19 10:35 AM, Adam D. Ruppe wrote:
 On Tuesday, 26 November 2019 at 15:28:38 UTC, Steven Schveighoffer wrote:
 Did you know this was valid syntax? I didn't.
I did not know already, but it is no surprise to me either because the colon works on almost every other attribute like that too... static if and version are similar according to teh grammar.
static if and version are not attributes. But actually, I didn't know that it works with version as well. Seems to also work with a debug condition according to grammar. What's weird is that it doesn't work in a function, but I guess those are considered a different part of the grammar. In any case, I probably will not be using it. But I did a double take when I saw it... -Steve
Nov 26 2019
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 26.11.19 16:50, Steven Schveighoffer wrote:
 On 11/26/19 10:35 AM, Adam D. Ruppe wrote:
 On Tuesday, 26 November 2019 at 15:28:38 UTC, Steven Schveighoffer wrote:
 Did you know this was valid syntax? I didn't.
I did not know already, but it is no surprise to me either because the colon works on almost every other attribute like that too... static if and version are similar according to teh grammar.
static if and version are not attributes. But actually, I didn't know that it works with version as well. Seems to also work with a debug condition according to grammar. What's weird is that it doesn't work in a function, but I guess those are considered a different part of the grammar.  In any case, I probably will not be using it. But I did a double take when I saw it... -Steve
static foreach(i;0..10): pragma(msg, ":P"); pragma(msg, "!");
Nov 26 2019
parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Tue, Nov 26, 2019 at 05:02:26PM +0100, Timon Gehr via Digitalmars-d wrote:
[...]
 static foreach(i;0..10):
 
 pragma(msg, ":P");
 pragma(msg, "!");
Ouch. That's ... ouch. Chalking this down to one of the darker corners of D. :-/ T -- Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. -- G. Steele
Nov 28 2019