Accepting function or delegate as function argument

Rene Zwanenburg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed May 4 08:23:20 PDT 2016


On Wednesday, 4 May 2016 at 14:54:39 UTC, chmike wrote:
> Two constructors, one accepting a function and the other one 
> accepting a delegate would do the job for the API. Is there a 
> simple method to convert a function pointer into a delegate 
> pointer that is also efficient ?

http://dlang.org/phobos/std_functional.html#.toDelegate

You can also make your constructor a template, constrain it on 
isCallable if you wish, and then use toDelegate. If the argument 
is already a delegate toDelegate will avoid doing extra work.


More information about the Digitalmars-d-learn mailing list