An issue with lazy delegates

Peter Alexander peter.alexander.au at gmail.com
Fri Jan 6 17:33:38 PST 2012


On 5/01/12 5:26 AM, Andrej Mitrovic wrote:
> The first call doesn't do anything because the delegate is wrapped
> inside of another delegate. I want this template to be versatile
> enough to be used by both lazy expressions and delegate literals, but
> I don't know how.

void test(T)(lazy T dg)
{
     static if (is(T == delegate))
         dg()();
     else
         dg();
}

void main()
{
     test( writeln("a") );
     test( { writeln("b"); } );
}


More information about the Digitalmars-d-learn mailing list