Last active
August 29, 2015 13:57
-
-
Save rikkimax/9501157 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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