Can we fix this?

Basile B. b2.temp at gmx.com
Thu Sep 30 03:32:07 UTC 2021


On Thursday, 30 September 2021 at 01:19:54 UTC, jfondren wrote:
> He doesn't exactly that it's not a bug, but that some design 
> that leads to it is desirable, and that some solutions are 
> undesirable. Specifically this part:
>
>>D closures are "by reference" rather than "by value". I make 
>>use of it being by reference all the time, as well as it being 
>>much more efficient. Changing it would likely break all sorts 
>>of code.

I think that D could do the captures by ref, always:

If the lambda lives longer than the parent scope of one of its 
capture then the capture must be copied to a new'd value, (as 
updating the original makes no sense btw) and otherwise it can be 
a true reference to the original thing.


More information about the Digitalmars-d mailing list