Sample code :
class A {
this(A) {}
}
class B {
}
typeof(null) foo(alias handler)(A a) {
handler(a);
B b;
return foo!handler(b);
}
typeof(null) foo(alias handler)(B) {
A a;
return foo!handler(a);
}
auto bar() {
A a;
foo!((stuff) {
new A(a);
})(a);
}
Note that foo instantiate itself with the same parameters every time, so it shouldn't go into infinite recursion.