On 01.03.2016 22:30, Tamas wrote:
struct Tag {}
template isTagged(S) {
enum bool isTagged =
delegate() {
foreach(attr; __traits(getAttributes, S)) {
static if (is(attr == Tag)) {
return true;
}
}
return false;
}();
}
This is off topic, but you can use std.meta.staticIndexOf to check if
something is in an alias seq:
----
template isTagged(S) {
import std.meta: staticIndexOf;
enum bool isTagged =
staticIndexOf!(Tag, __traits(getAttributes, S)) >= 0;
}
----
And for UDAs in particular there is std.traits.hasUDA:
----
template isTagged(S) {
import std.traits: hasUDA;
enum bool isTagged = hasUDA!(S, Tag);
}
----