reasoning of evaluating code after return in current block (static if return)
Adam D. Ruppe via Digitalmars-d
digitalmars-d at puremagic.com
Sun May 7 16:20:26 PDT 2017
On Sunday, 7 May 2017 at 22:34:14 UTC, bastien penavayre wrote:
> Why is the code following "return true" evaluated ?
It isn't evaluated, it is just compiled. The compile happens
before it is run, so it doesn't really know if it is reachable
yet.
> ClLinearExpression opBinary(string op) (double constant)
> {
> static if (op == "+")
> return new ClLinearExpression(this, 1, constant);
> else
> static if (op == "-")
> return new ClLinearExpression(this, 1,
> -constant);
> else
> static if (op == "*")
> return new ClLinearExpression(this,
> constant, 0);
> else
> static if (op == "/")
> return new ClLinearExpression(this, 1.0
> / constant, 0);
> }
I would just write it `else static if` all on one line and not
indent further. Then it barely looks any different anyway.
More information about the Digitalmars-d
mailing list