View mode: basic / threaded / horizontal-split · Log in · Help
October 12, 2007
Re: Feature Request: Support delegate literal context skipping
downs Wrote:

> In the following situation
> 
> class Foo {
>   int e;
>   void delegate() bar() {
>     return { e++; };
>   }
> }
> 
> the delegate literal will not work. This is because its context is bar,
> and bar has ended. But the literal doesn't *need* anything from bar.
> 
> Because of this, I propose in situations where a delegate literal
> doesn't access the immediate surrounding stack frame, its context be the
> first frame (or class) that it does access.
> So in this example, { e++; } 's .ptr would point at the respective
> instance of Foo, allowing this to work.
> 
> Disadvantages: None
> Advantages: potentially highly helpful with user interface code, where
> such callbacks are commonplace.

Disadvantages: That doesn't sound easy to implement.

I like the idea a lot, though.
Top | Discussion index | About this forum | D home