On Saturday, 4 June 2022 at 21:17:56 UTC, SealabJaster wrote:
>On Saturday, 4 June 2022 at 19:54:48 UTC, Dukc wrote:
>auto number = 200;
auto myVar = type == "as-is"?
number:
{ number *= 2;
number += 2;
number /= 2;
number = number > 300 ? 200 : 100;
return number;
}();
This next question comes from a place of ignorance: What is the codegen like for this code? Would is allocate a closure on the GC before performing the execution, or are the compilers smart enough to inline the entire thing?
LDC is able to inline the lambda and then optimize away the allocation. DMD is not.