toDelegate() for D1
Simen kjaeraas
simen.kjaras at gmail.com
Fri Jan 14 18:44:59 PST 2011
Moritz Warning <moritzwarning at web.de> wrote:
> My tangofied of this code works, maybe it's a lib bug?
> On the other hand, is the delegate allocated on the stack?
> Anyway, here is another way:
>
> 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;
> }
Man, that's almost as ugly as some of the things I do. :p
That's plenty fine if it works, though.
--
Simen
More information about the Digitalmars-d-learn
mailing list