Skip to content

Instantly share code, notes, and snippets.

@rikkimax
Last active August 29, 2015 13:57
Show Gist options
  • Save rikkimax/9501157 to your computer and use it in GitHub Desktop.
Save rikkimax/9501157 to your computer and use it in GitHub Desktop.
mixin template MixinUDACheck(T) {
mixin("bool is" ~ T.stringof ~ " (C, string f)(C c = C.init)" ~ q{{
foreach(UDA; __traits(getAttributes, mixin("c." ~ f))) {
static if (is(UDA == T)) {
return true;
}
}
return false;
}});
}
struct Test {
}
class Test2 {
@Test
uint x;
uint y;
}
mixin MixinUDACheck!Test;
void main() {
assert(isTest!(Test2, "x"));
assert(!isTest!(Test2, "y"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment