best D way to port C style array of void*

Steven Schveighoffer schveiguy at yahoo.com
Tue Feb 5 20:27:42 PST 2013


On Tue, 05 Feb 2013 23:17:59 -0500, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:


> e.g.:
>
> import std.stdio;
>
> void callit(void delegate() dg)
> {
>      // call delegate with context pointer
>      dg();
> }
>
> void main()
> {
>      int x;
>      auto dg = ()=>writeln(++x); // create a delegate using a lambda  
> function
>      callit(dg);
>      callit(dg);
>      callit(dg);
>      callit(dg);
> }

Forgot to say, the output here would be:

1
2
3
4

-Steve


More information about the Digitalmars-d-learn mailing list