Re: CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
On Thursday, 7 May 2020 at 17:59:30 UTC, Paul Backus wrote: 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

Re: CTFE and Static If Question

2020-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 07, 2020 at 05:34:21PM +0200, ag0aep6g via Digitalmars-d-learn wrote: [...] > Compared with LDC and GDC, DMD has a poor optimizer, [...] DMD's optimizer is the whipping boy around here, but to be fair, it is poor only when it comes to aggrssive inlining and optimizing loops. Other tha

Re: CTFE and Static If Question

2020-05-07 Thread Paul Backus via Digitalmars-d-learn
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, co

Re: CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:34:21 UTC, ag0aep6g wrote: [snip] The `static if` is guaranteed to be evaluated during compilation. That means, `foo!y0` effectively becomes this: auto foo(int rt) { return rt + 1; } There is no such guarantee for `foo(rt, y0)`. It doesn't matter that y0 is

Re: CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
On Thursday, 7 May 2020 at 15:29:01 UTC, H. S. Teoh wrote: [snip] You explained things very well, thanks.

Re: CTFE and Static If Question

2020-05-07 Thread ag0aep6g via Digitalmars-d-learn
On 07.05.20 17:00, 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)? auto foo(bool rtct)(int rt) {     static if (rtct)     return rt + 1;     else     return rt; } auto foo(int rt, bool rtct) {

Re: CTFE and Static If Question

2020-05-07 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, May 07, 2020 at 03:00:18PM +, jmh530 via Digitalmars-d-learn wrote: > I am curious how ctfe and static ifs interact. Then you should find this article helpful: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time > In particular, if an enum bool passed as a tem

CTFE and Static If Question

2020-05-07 Thread jmh530 via Digitalmars-d-learn
I am curious how ctfe and static ifs interact. In particular, if an enum bool passed as a template parameter or run-time one will turn an if statement into something like a static if statement (perhaps after the compiler optimizes other code away). In the code below, I am a function that takes