hasMember

Checks for presence of method/field with specified name in aggregate.

In D1 most common idiom is to simply check for is(typeof(T.something)) but in D2 it can backfire because of UFCS as global names are checked too - thus built-in __traits(hasMember) is used instead, which was not available in D1.

template hasMember (
T
istring name
) {}

Members

Manifest constants

hasMember
enum hasMember;
Undocumented in source.

Parameters

T

aggregate type to check

name

method/field name to look for

Return Value

true if aggregate T has a method/field with an identifier name

Examples

struct S
{
    void foo () { }
    int x;
}

static assert ( hasMember!(S, "foo"));
static assert ( hasMember!(S, "x"));
static assert (!hasMember!(S, "bar"));

Meta