guard clause style static if
rikki cattermole
rikki at cattermole.co.nz
Sat Jul 7 13:03:32 UTC 2018
On 08/07/2018 12:54 AM, kdevel wrote:
> On Saturday, 7 July 2018 at 12:46:08 UTC, rikki cattermole wrote:
>> On 08/07/2018 12:40 AM, kdevel wrote:
>>> Interesting alternative
>>
>> That was not an alternative.
>> That is what your code was doing.
>
> What my original code was supposed to do. But it did not compile.
>
> Error: array index [0] is outside array bounds [0 .. 0]
> Error: string slice [1 .. 0] is out of bounds
>
> My question is if it is intentionally failing to compile a static if
> guard clause.
There is no such thing as a static if guard clause.
static if does not exist at runtime, only compile time. So when you
erase it (CT -> RT)...
void func() {
static if(true) {
return;
}
func2();
}
becomes:
void func() {
return;
func2();
}
Which is clearly an error. Hence why you need to add else block.
More information about the Digitalmars-d-learn
mailing list