Re: Copy a struct and its context

2016-09-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/13/16 5:01 PM, Yuxuan Shui wrote: For example, a common use case might be I want to capture everything by value. In stead of adding all the fields by hand and passing them to the constructor, I want the compiler to do it for me. i.e. I wish I could (borrowing C++ syntax): struct A[=] {

Re: Copy a struct and its context

2016-09-13 Thread Yuxuan Shui via Digitalmars-d-learn
On Tuesday, 13 September 2016 at 20:36:22 UTC, Steven Schveighoffer wrote: On 9/13/16 4:11 PM, Yuxuan Shui wrote: On Tuesday, 13 September 2016 at 20:00:40 UTC, Steven Schveighoffer wrote: Not familiar with C++ lambda. You can always "specify" how to capture the data by directly declaring it:

Re: Copy a struct and its context

2016-09-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/13/16 4:11 PM, Yuxuan Shui wrote: On Tuesday, 13 September 2016 at 20:00:40 UTC, Steven Schveighoffer wrote: 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; }

Re: Copy a struct and its context

2016-09-13 Thread Yuxuan Shui via Digitalmars-d-learn
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

Re: Copy a struct and its context

2016-09-13 Thread Basile B. via Digitalmars-d-learn
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:

Re: Copy a struct and its context

2016-09-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 9/13/16 3:42 PM, Yuxuan Shui wrote: 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

Re: Copy a struct and its context

2016-09-13 Thread Yuxuan Shui via Digitalmars-d-learn
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:

Re: Copy a struct and its context

2016-09-12 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: Copy a struct and its context

2016-09-12 Thread Ali Çehreli via Digitalmars-d-learn
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). And bliting a struct obviously doesn't do a deep copy of its context. So my question is, is there a

Re: Copy a struct and its context

2016-09-11 Thread Rene Zwanenburg via Digitalmars-d-learn
On Sunday, 11 September 2016 at 05:44:13 UTC, 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). And bliting a struct obviously doesn't do a deep copy of its context. So

Copy a struct and its context

2016-09-10 Thread Yuxuan Shui via Digitalmars-d-learn
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). And bliting a struct obviously doesn't do a deep copy of its context. So my question is, is there a way to deep copy the context of a