The future of lambda delegates
Walter Bright
newshound at digitalmars.com
Wed Aug 16 14:24:18 PDT 2006
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.
> // 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