1 module nxt.attr; 2 3 struct sillyWalk { int i; } 4 5 enum isSillyWalk(alias T) = is(typeof(T) == sillyWalk); 6 7 import std.typetuple; 8 alias hasSillyWalk(alias what) = anySatisfy!(isSillyWalk, __traits(getAttributes, what)); 9 enum hasSillyWalk(what) = false; 10 11 alias helper(alias T) = T; 12 alias helper(T) = T; 13 14 /** Find all functions with certain attribute. 15 See_Also: https://stackoverflow.com/questions/25555329/d-finding-all-functions-with-certain-attribute 16 */ 17 void allWithSillyWalk(alias a, alias onEach)() 18 { 19 pragma(msg, "Processing: " ~ a.stringof); 20 foreach(memberName; __traits(allMembers, a)) 21 { 22 // guards against errors from trying to access private stuff etc. 23 static if(__traits(compiles, __traits(getMember, a, memberName))) 24 { 25 alias member = helper!(__traits(getMember, a, memberName)); 26 27 // pragma(msg, "looking at " ~ memberName); 28 import std..string; 29 static if(!is(typeof(member)) && member.stringof.startsWith("module ")) 30 { 31 enum mn = member.stringof["module ".length .. $]; 32 mixin("import " ~ mn ~ ";"); 33 allWithSillyWalk!(mixin(mn), onEach); 34 } 35 36 static if(hasSillyWalk!(member)) 37 { 38 onEach!member; 39 } 40 } 41 } 42 }