Let's get the semantic around closure fixed.
Ola Fosheim Grostad
ola.fosheim.grostad at gmail.com
Tue May 18 21:37:15 UTC 2021
On Tuesday, 18 May 2021 at 21:11:08 UTC, Ola Fosheim Grostad
wrote:
> On Tuesday, 18 May 2021 at 20:26:26 UTC, Steven Schveighoffer
> wrote:
>> On 5/18/21 4:07 PM, Ola Fosheim Grostad wrote:
>> No, it was correct before the hack. Code which captured a
>> struct that would be destroyed outside the scope just wouldn't
>> compile. Now it does.
>
> Btw in C++ lambdas should not outlive captured references, if
> you want that you need to make a copy, aka capture by value.
> That is a clean solution to the destructor problem as the
> destructor will be called when you expect it to.
>
> I guess that is the only sensible solution.
Another correct solution is to track destruction and use a
runtime liveness test before allowing object access. This would
be more of a high level feature though. So you capture an object
by reference, but you are not allowed to access a dead object.
More information about the Digitalmars-d
mailing list