implicitly convert function pointers to delegates
Moritz Warning
moritzwarning at web.de
Sun Oct 26 10:38:30 PDT 2008
Hi,
some people discovered that functions can be wrapped into delegates
without allocation.
Here is one out of several similar solutions:
R delegate(T) toDg(R, T...)(R function(T) fp) {
struct dg {
R opCall(T t) {
return (cast(R function(T)) this) (t);
}
}
R delegate(T) t;
t.ptr = fp;
t.funcptr = &dg.opCall;
return t;
}
I would like to ask if we can get this into the language?
It would make working with delegates and function pointers much more
easier when function pointers implicitly convert to delegates when they
"have to".
More information about the Digitalmars-d
mailing list