static if and early exit from function doesn't seem to work?

Adam D. Ruppe destructionator at gmail.com
Sun Dec 31 13:47:32 UTC 2017


On Sunday, 31 December 2017 at 13:32:03 UTC, aliak wrote:
> So it seems it tries to compile the statements below the check 
> on V.length even though it's guaranteed to be true and there's 
> a return statement inside the if.

Yeah, static if includes or excludes code independently at 
compile time.

So what you wrote there would be like, assuming the first to 
static ifs pass:

auto concat(R, V...)(R range, V values) if (isInputRange!R) {
     import std.range: chain, ElementType;
         return range;
         return range.chain(values[0]).concat(values[1..$]);
}


The code is still there, even if it isn't reached due to an early 
return, and thus still must compile.


Using else static if means it won't be generated.


More information about the Digitalmars-d-learn mailing list