On 10/29/13, 22:42, David Nadlinger wrote:
On Tuesday, 29 October 2013 at 21:41:25 UTC, Lionello Lunesu wrote:
So a copy should have been made of the live object, not the destructed
one. Correct?

No. There should only be one struct instance, the one living (forever)
in the closure context.

David

Why? It's a struct. It should be completely fine to create a copy [on the heap] for the closure context.

The way I see closure is that any referenced locals become hidden arguments. Imagine an implicit ", S s" in the closure's parameter list. Everybody would expect 's' (being a value type) to be a copy.

If you want to ensure there's only one instance, you either need to use class instead of struct, or allocate 's' on the heap and use a pointer to S.

L.

Reply via email to