import std.stdio; void test(T)(lazy T dg) { test2(dg); }
void test2(T)(lazy T dg) { dg(); // nothing happens dg()(); // have to use double-invocation instead } void main() { test({ writeln("test"); }); } Do you think it would be possible for the compiler to avoid wrapping delegates into another delegate? I'm having this problem with this sort of template: import std.conv; import std.string; auto onFailThrow(E, T)(lazy T dg) { try { static if (is(ReturnType!T == void)) dg(); else return dg(); } catch (Exception ex) { throw new E(ex.msg); } } void main() { string x = "x"; string y = "y"; onFailThrow!Exception({ to!int(x); }); onFailThrow!Exception(to!int(y)); } 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. If I write the same template but with "lazy" stripped off I'll have conflicting templates, but I don't know how I would write constraints to separate the two. Any ideas?