Let's get the semantic around closure fixed.

Ola Fosheim Grostad ola.fosheim.grostad at gmail.com
Wed May 19 21:56:19 UTC 2021


On Wednesday, 19 May 2021 at 20:19:22 UTC, deadalnix wrote:
> In fact, even in C++, you'll find yourself with an allocation 
> per loop if you do:
>
> std::vector<std::function<void()>> funs;
> for (int i = 0; i < 10; i++) {
>     funs.push_back([i]() { printf("%d\n", i); });
> }
>
> The instantiation of std::function here will allocate.

I think it is implementation defined how large the internal 
buffer in std::function is? So it will allocate if it is too 
large? But yeah, it is ugly, I never use it. Usually one can 
avoid it..




More information about the Digitalmars-d mailing list