Delegate, scope and associative array

Edwin van Leeuwen via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 3 00:24:18 PDT 2014


On Tuesday, 3 June 2014 at 07:00:35 UTC, Ali Çehreli wrote:
> Here is a workaround:
>
> unittest {
>     size_t delegate()[size_t] events;
>
>     auto makeClosure(size_t i) {
>         return { return i; };
>     }
>
>     foreach( i; 1..4 ) {
>         events[i] = makeClosure(i);
>     }
>
>     assert( events[1]() == 1 );
> }
>
> void main()
> {}
>
> Ali

Thank you Ali, that works beautifully and can be easily adapted 
to the original (more complicated) case.

Cheers, Edwin


More information about the Digitalmars-d-learn mailing list