On Friday, 15 February 2019 at 17:28:45 UTC, H. S. Teoh wrote:
On Fri, Feb 15, 2019 at 05:40:39PM +0100, ag0aep6g via
Digitalmars-d-learn wrote:
Your fun_to_dlg fails when the function has parameters.
Yes. Delegates are basically syntactic sugar for a function
pointer with an implicit first p
On Fri, Feb 15, 2019 at 05:40:39PM +0100, ag0aep6g via Digitalmars-d-learn
wrote:
> On 15.02.19 15:20, Bastiaan Veelo wrote:
> > Exploiting this, it is possible to explicitly convert a function
> > pointer into a delegate [2]:
> > ```
> > Ret delegate(Args args) fun_to_dlg(Ret, Args...)(Ret functi
On Friday, 15 February 2019 at 16:40:39 UTC, ag0aep6g wrote:
Your fun_to_dlg fails when the function has parameters.
Hah ok. std.functional.toDelegate() does work in its place though.
As far as I see, it would be possible make the conversion would
work by changing how a delegate's context is
On 15.02.19 15:20, Bastiaan Veelo wrote:
Exploiting this, it is possible to explicitly convert a function pointer
into a delegate [2]:
```
Ret delegate(Args args) fun_to_dlg(Ret, Args...)(Ret function(Args args)
fun)
{
Ret delegate(Args) dlg;
dlg.funcptr = fun;
return dlg;
}
```
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() {ret
On Friday, 15 February 2019 at 14:20:44 UTC, Bastiaan Veelo wrote:
Given a function taking a delegate, for example
```
int fun(int delegate() dg) {return dg();}
```
Sometimes we need to call `fun` with a pointer to a nested
function and other times with a pointer to a top level
function. As f
Given a function taking a delegate, for example
```
int fun(int delegate() dg) {return dg();}
```
Sometimes we need to call `fun` with a pointer to a nested
function and other times with a pointer to a top level function.
As function pointers do not implicitly convert to delegates, this
does