D equivalent of C++ bind ?

André via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 10 09:21:45 PDT 2016


On Tuesday, 10 May 2016 at 15:33:03 UTC, chmike wrote:
> Thanks. This does the job but it's not as concise.

I've never missed C++'s bind functionality because D has first 
class support for delegates.

If async_task is changed to the following:

void async_task(void delegate(int error) cb) { . . . while cb(0) 
. . . }

You could just adapt a call to it using a lambda function:

async_task( (error) => myCb(error, count) );

D makes sure the enclosing stack is copied to the heap and count 
is reachable. Maybe this helps...

Regards,
André


More information about the Digitalmars-d-learn mailing list