optional assignment

Quirin Schroll qs.il.paperinik at gmail.com
Wed Feb 5 12:22:46 UTC 2025


On Wednesday, 5 February 2025 at 12:20:33 UTC, Quirin Schroll 
wrote:
> On Sunday, 2 February 2025 at 03:30:17 UTC, Walter Bright wrote:
>> ```
>> if (!a) a = b;
>> ```
>>
>> Doesn't seem that bad. I did some searches and found hardly 
>> any instances of it, though that was across the dmd sources.
>
> […]
> ```d
> int getField3()
> {
>     auto ref field = _field;
>     if (!field)
>     {
>         field = new int(10);
>     }
>     return *field;
> }
> ```

This is the actually equivalent code if we’re pedantic.




More information about the dip.ideas mailing list