Do you think if statement as expression would be nice to have in D?

SealabJaster sealabjaster at gmail.com
Sat Jun 4 21:17:56 UTC 2022


On Saturday, 4 June 2022 at 19:54:48 UTC, Dukc wrote:
> ```D
> 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?


More information about the Digitalmars-d mailing list