On Sunday, 23 March 2014 at 12:53:39 UTC, Dicebot wrote:
template isSomething(T)
{
    enum isSomething =
                is(typeof(__traits(getMember, T, "doSomething")) == function)
&& is(typeof(&__traits(getMember, T, "doSomething")) : void function(Unrelated*));
}

That won't necessarily work in the presence of overloaded functions since getMember only gets one of them.

You could though do this:

template isSomething(T) {
    bool checker() {
foreach(overload; __traits(getOverloads, T, "doSomething")) static if(is(typeof(overload) == void function(Unrelated*)))
                       return true;
        return false;
    }
    enum isSomething = checker();
}

getOverloads returns an empty tuple for non-functions so you don't even have to check that ahead of time.

Reply via email to