The OpenD Programming Language

hasFunctionAttributes

Checks whether a function has the given attributes attached.

template hasFunctionAttributes (
args...
) if (
args.length > 0 &&
isCallable!(args[0])
&&
allSatisfy!(isSomeString, typeof(args[1 .. $]))
) {
enum bool hasFunctionAttributes;
}

Parameters

args

Function to check, followed by a variadic number of function attributes as strings

Return Value

true, if the function has the list of attributes attached and false otherwise.

Examples

real func(real x) pure nothrow @safe;
static assert(hasFunctionAttributes!(func, "@safe", "pure"));
static assert(!hasFunctionAttributes!(func, "@trusted"));

// for templates attributes are automatically inferred
bool myFunc(T)(T b)
{
    return !b;
}
static assert(hasFunctionAttributes!(myFunc!bool, "@safe", "pure", "@nogc", "nothrow"));
static assert(!hasFunctionAttributes!(myFunc!bool, "shared"));

See Also

Meta