xxxxxxxxxx
int function() foo = { return 42; };
int delegate() bar = { return 43; };
int delegate() baz;
int fun(int delegate() dg) {return dg();}
int top_level() {return -1;}
Ret delegate(Args args) fun_to_dlg(Ret, Args...)(Ret function(Args args) fun)
{
Ret delegate(Args) dlg;
dlg.funcptr = fun;
return dlg;
}
void main()
{
assert(foo() == 42);
assert(bar() == 43);
assert(baz is null);
assert(bar.ptr is null); // null frame pointer
fun(bar);
//fun(foo); // cannot pass argument foo of type int function() to parameter int delegate()
//fun(cast(int delegate())foo); // cannot cast expression foo of type int function() to int delegate()
baz = bar;
//baz = foo; // cannot implicitly convert expression foo of type int function() to int delegate()
//baz = &test; // cannot implicitly convert expression & test of type int function() to int delegate()
baz.funcptr = &top_level;
assert(baz.ptr is null);
assert(baz() == -1);
assert(fun(baz) == -1);
//fun(&top_level); // cannot pass argument & top_level of type int function() to parameter int delegate() dg
assert(fun(fun_to_dlg(&top_level)) == -1);
}