Generalizing over function pointers and delegates
Bastiaan Veelo
Bastiaan at Veelo.net
Fri Feb 15 14:37:35 UTC 2019
On Friday, 15 February 2019 at 14:30:45 UTC, Alex wrote:
>
> There is
> https://dlang.org/library/std/functional/to_delegate.html
Ah, there it is :-) Thanks.
A templated function also works.
```
int genfun(F)(F dg) {return dg();}
int top_level() {return -1;}
void main()
{
int nested() {return -2;}
assert(genfun(&top_level) == -1);
assert(genfun(&nested) == -2);
}
```
More information about the Digitalmars-d-learn
mailing list