On Tuesday, 13 September 2016 at 20:00:40 UTC, Steven
Schveighoffer wrote:
On 9/13/16 3:42 PM, Yuxuan Shui wrote:
[...]
There's nothing in the language to prevent this optimization.
[...]
Again, could be clearer. But the fact that both the function
and the struct affect the same data kind of dictates it needs
to be a reference.
[...]
Not familiar with C++ lambda. You can always "specify" how to
capture the data by directly declaring it:
auto foo()
{
int x;
static struct S
{
int x;
}
return S(x);
}
It just feels a bit tedious to do something manually while the
compiler have enough information to do it for me.
In D, if you have a closure, it's going to be heap allocated.
Just the way it is. If you don't want that, you have to avoid
them.
-Steve