Check for presence of function

Steve Teale steve.teale at britseyeview.com
Sun Mar 23 05:40:51 PDT 2014


What's the cool/idiomatic D way to test at compile time if a 
struct has a member function with a particular signature? Along 
the lines of:

struct Unrelated
{
    ...
}

template isSomething(T)
{
     enum bool isSomething = is(typeof(
     (inout int = 0)
     {
        T???; // has a function void doSomething(Unrelated* up);
        // etc
     }));
}

struct Thingie
{
    ...
}

static assert(isSomething!(Thingie));

Thanks
Steve


More information about the Digitalmars-d-learn mailing list