isCovariantWith

Determines whether the function type F is covariant with G, i.e., functions of the type F can override ones of the type G.

template isCovariantWith (
F
G
) if (
is(F == function) &&
is(G == function)
||
is(F == delegate) &&
is(G == delegate)
||
isFunctionPointer!F &&
isFunctionPointer!G
) {
static if(is(F : G))
enum isCovariantWith;
static if(!(is(F : G)))
enum isCovariantWith;
}

Examples

interface I { I clone(); }
interface J { J clone(); }
class C : I
{
    override C clone()   // covariant overriding of I.clone()
    {
        return new C;
    }
}

// C.clone() can override I.clone(), indeed.
static assert(isCovariantWith!(typeof(C.clone), typeof(I.clone)));

// C.clone() can't override J.clone(); the return type C is not implicitly
// convertible to J.
static assert(!isCovariantWith!(typeof(C.clone), typeof(J.clone)));

Meta