hasField - multiple declarations

Function hasField

Returns true if a field can be found on aggregate with the given fieldName, false otherwise.

auto hasField(alias aggregate, string fieldName)() pure nothrow @safe
if (isAggregate!aggregate || isModule!aggregate);

Example

struct S {
    long id;
    int age;
    string name() {
        return "name";
    }
}

hasField!(S, "id"); // returns true
hasField!(S, "name"); // returns false

Function hasField

Returns true if a field can be found on aggregate filtered with the given predicate, false otherwise.

auto hasField(alias aggregate, alias predicate)() pure nothrow @safe
if ((isAggregate!aggregate || isModule!aggregate) && is(typeof(unaryFun!predicate)));

Example

struct S {
    long id;
    int age;
    string name() {
        return "name";
    }
}

hasField!(S, field => isNumeric!(field.type)); // returns true
hasField!(S, field => is(field.type == string)); // returns false