skinny delegates
Steven Schveighoffer
schveiguy at gmail.com
Sat Aug 4 13:52:54 UTC 2018
On 8/4/18 9:07 AM, kinke wrote:
> On Saturday, 4 August 2018 at 12:21:18 UTC, Steven Schveighoffer wrote:
>> You don't even need to make a copy to show problems, the context isn't
>> passed by reference:
>>
>> const r1 = dg();
>> const r2 = dg();
>>
>> assert(r1 == 43 && r2 == 44); // would fail with optimization.
>>
>
> This depends on the implementation; assuming that captured `x`
> represents the `*cast(int*) context` lvalue, this example would work.
No, it depends on and is dictated by D's delegate system. The delegate
receives the context pointer by value. If you wanted it to accept the
context by reference, you would have to have something other than a D
delegate.
-Steve
More information about the Digitalmars-d
mailing list