The future of lambda delegates
BCS
BCS at pathlink.com
Wed Aug 16 15:36:25 PDT 2006
Walter Bright wrote:
> BCS wrote:
>
>> BTW how do you construct a delegate literal inside of a class method
>> that uses "this" as it's context, rather than the frame pointer?
>>
>> class Foo
>> {
>> int i;
>> int delegate() fig(){ return {return i;}; }
>
>
> It uses the frame pointer of fig() to access fig()'s this. Of course,
> though, this will currently fail because fig() is exited before the
> delegate is called.
>
a.k.a. It can't be done?
>> // int delegate() fig(){ return this.{return i;}; } // this maybe?
>> }
>>
>> void main()
>> {
>> auto foo = new Foo;
>> auto farm = foo.fig;
>>
>> foo.i = 5;
>> auto i = farm(); // valid if context is "foo"
>> assert(i == 5);
>> }
More information about the Digitalmars-d
mailing list