diff --git a/std/functional.d b/std/functional.d index ed807b23a30..534b99913dc 100644 --- a/std/functional.d +++ b/std/functional.d @@ -1819,6 +1819,10 @@ if (isCallable!(F)) { return toDelegate(&fp.opCall); } + else static if (is(typeof(&fp.opCall!()))) + { + return toDelegate(&fp.opCall!()); + } else { alias DelType = typeof(&(new DelegateFaker!(F)).doIt); @@ -1949,6 +1953,20 @@ if (isCallable!(F)) } } + +@system unittest +{ + static struct S1 { static void opCall()() { } } + static struct S2 { static T opCall(T = int)(T x) {return x; } } + + S1 i1; + const dg1 = toDelegate(i1); + dg1(); + + S2 i2; + assert(toDelegate(i2)(0xBED) == 0xBED); +} + /** * Passes the fields of a struct as arguments to a function. *