View source code
Display the source code in std/traits.d from which this page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone.

Enum member std.traits.hasFunctionAttributes

Checks whether a function has the given attributes attached.

enum hasFunctionAttributes(args...) = () { import std.algorithm.searching : canFind; import std.range : only; enum funcAttribs = only(__traits(getFunctionAttributes, args[0])); static foreach (attribute; args[1..__dollar]) { if (!funcAttribs.canFind(attribute)) return false; } return true; } ();

Parameters

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

Returns

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

See Also

functionAttributes

Example

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"));

Authors

Walter Bright, Tomasz Stachowiak (isExpressions), Andrei Alexandrescu, Shin Fujishiro, Robert Clipsham, David Nadlinger, Kenji Hara, Shoichi Kato

License

Boost License 1.0.