On Tuesday, 13 September 2016 at 01:32:19 UTC, Steven
Schveighoffer wrote:
On 9/12/16 4:11 PM, Ali Çehreli wrote:
On 09/10/2016 10:44 PM, Yuxuan Shui wrote:
I recently noticed nested struct capture its context by
reference
(which, BTW, is not mentioned at all here:
https://dlang.org/spec/struct.html#nested).
" It has access to the context of its enclosing scope (via an
added hidden field)."
It needs to be a reference. Otherwise, you store the entire
stack frame in the struct? That wouldn't be a "field". It also
has write access to the context:
Why not just capture the variables that are actually been
referenced? Also being a field doesn't put limits on the size of
the "field".
I like how C++ lambda lets you choose what variables to capture,
and how are they captured. I'm little disappointed that D doesn't
let me do the same.