DIP23 draft: Fixing properties redux

Artur Skawina art.08.09 at gmail.com
Sun Feb 3 07:58:46 PST 2013


On 02/03/13 16:04, Steven Schveighoffer wrote:
> On Sun, 03 Feb 2013 08:04:10 -0500, Timon Gehr <timon.gehr at gmx.ch> wrote:
> 
>> T delegate() f = &a.prop -> auto f = ()=>a.prop;
>> T delegate(T) f = &a.prop -> auto f = (T x)=>a.prop=x;
> 
> I don't like this solution.  You are creating a dummy delegate function, and moving the stack frame into the heap, just so you can get a delegate to an already existing function.

Not really, it just needs to be specced properly. There's already a similar
issue with lazy args, and the natural solution is the same.
A trivial "{ return any_kind_of_hidden_delegate; }" lambda is functionally
equivalent to a "cast(delegate)any_kind_of_hidden_delegate" expression. The
"optimization" just needs to be mandated, so that you can rely on the "real"
delegate being forwarded (ie the .funcptr should be the real one and such
lambda shouldn't trigger heap allocation).

artur


More information about the Digitalmars-d mailing list