Newbie initial comments on D language - delegate

Jarrett Billingsley kb3ctd2 at yahoo.com
Tue Jan 29 11:22:05 PST 2008


"Russell Lewis" <webmaster at villagersonline.com> wrote in message 
news:fnnivs$11k$1 at digitalmars.com...
> Yeah, I've seen people use the union magic to make it work without a new. 
> It's a cool trick, but it makes me squirm when I think about portability. 
> So I use a general version, using closures (note that my template uses a 
> fixed "void" return code...previous posts in the NG can show you how to 
> IFTI non-void return codes):
>
> void delegate(TPL) convert(TPL...)(void function(TPL) func)
> {
>   return delegate void(TPL args)
>          {
>            func(args);
>          };
> }
>
> // note that 'func' is put on the heap automatically by the closure
> // mechanism in the compiler.

For those who aren't aware, this will only work in D2, not D1.  In D1 you'll 
probably get an access violation upon attempting to call the returned 
delegate. 





More information about the Digitalmars-d mailing list