CTFE and Static If Question

Paul Backus snarwin at gmail.com
Thu May 7 17:59:30 UTC 2020


On Thursday, 7 May 2020 at 15:00:18 UTC, jmh530 wrote:
> Does foo!y0(rt) generate the same code as foo(rt, y0)?
>
> How is the code generated by foo(rt, x0) different from 
> foo(rt,y0)?

You can look at the generated code using the Compiler Explorer at 
d.godbolt.org. Here's a link to your example, compiled with ldc, 
with optimizations enabled:

https://d.godbolt.org/z/x5K7P6

As you can see, the non-static-if version has a runtime 
comparison and a conditional jump, and the static-if version does 
not. However, it doesn't make a difference in the end, because 
the calls have been optimized out, leaving an empty main function.


More information about the Digitalmars-d-learn mailing list