guard clause style static if

Steven Schveighoffer schveiguy at yahoo.com
Tue Jul 10 00:11:27 UTC 2018


On 7/7/18 7:28 AM, kdevel wrote:
> It appears not to be possible to use static if in "guard clause style" 
> as in
> 
>     void bar (T ...) (T args)
>     {
>        static if (args.length == 0)
>           return;
> 
>        writeln (args [0]);
>        return bar (args [1 .. $]);
>     }
> 
> Is this intended?

Yes.

Try just a normal if -- it will have the same effect (the optimizer will 
eliminate the dead code), but will compile.

Of course, you have to fix your second part to only return bar if 
args.length > 0!

-Steve


More information about the Digitalmars-d-learn mailing list