Let's get the semantic around closure fixed.

Ola Fosheim Grostad ola.fosheim.grostad at gmail.com
Thu May 20 15:24:46 UTC 2021


On Thursday, 20 May 2021 at 13:48:01 UTC, deadalnix wrote:
> It is more tricky, but some implementation of std::function do 
> that. If what's captured is small enough, they store it in 
> place, if it is larger, they allocate.

Yes, but sizeof std::function is always the same?

> It is not mandated by the standard and the size after which 
> they'll allocate is implementation defined when they do, not 
> under the user's control.

True, but D could be smarter and do something similar, but allow 
the size to vary so that you can save memory. And if you only 
assign once, then the cost of having a larger buffer in the 
delegate is smaller than if you do many assignments.

D can be smarter than C++ because it can generate IR for all D 
files, I think?


More information about the Digitalmars-d mailing list