templated overload of opAssign

tsbockman thomas.bockman at gmail.com
Mon Apr 5 21:14:14 UTC 2021


On Monday, 5 April 2021 at 05:22:22 UTC, frame wrote:
> On Sunday, 4 April 2021 at 18:05:04 UTC, tsbockman wrote:
>
>>
>> Thus, the solution is to use an explicit `delegate` instead of 
>> `lazy`:
>
>
> Yes, I forgot to mention that.
> Could you please explain why you set 'scope' here? Isn't it 
> wanted to keep references here?

`scope` here indicates that no references to the `f` delegate 
itself will be escaped from `opAssign`, giving the caller the 
option of allocating the closure on the stack.

`opAssign` may retain a reference to an `Exception` thrown by the 
delegate, but that's OK because the `Exception` is not part of 
the `f` delegate data structure, not even indirectly or 
transitively. (I can explain/justify this in more detail if that 
still doesn't make sense.)


More information about the Digitalmars-d-learn mailing list