On Friday, 1 August 2014 at 17:17:57 UTC, H. S. Teoh via Digitalmars-d-learn wrote:
        if (is(typeof(f(x))) || is(typeof(x.f)))

Here's my try:

template isCallableWith(alias fun, T)
{
enum bool isCallable = is(typeof(fun(T.init))) || is(typeof(T.init.fun));
}
unittest {
    auto sqr(T)(T x) { return x*x; }
    auto xf = isCallableWith!(sqr, int);
}

but errs as

traits_ex.d(182,15): Error: cannot infer type from template instance isCallableWith!(sqr, int)

Could someone, please, explain how to f and x should be passed in a template here?

A complete implementation of, say isCallableWith, would be nice. :)

Reply via email to