Using traits get a list of methods and filter out the member vars.

Gary Willoughby dev at nomad.so
Sun Sep 8 06:20:10 PDT 2013


When iterating through class members using traits how do you 
filter out the member vars to only get a list of methods. I think 
i've solved it in the code below but it feels like i am abusing 
MemberFunctionsTuple. Is this the correct way to do this?

private template Methods(T, int index = 0)
{
	private string getMethods()
	{
		string code = "";
		static if (index < __traits(allMembers, T).length)
		{
			static if (MemberFunctionsTuple!(T, __traits(allMembers, 
T)[index]).length)
			{
				code ~= __traits(allMembers, T)[index] ~ "\n";
			}
			code ~= Methods!(T, index + 1);
		}
		return code;
	}
	enum Methods = getMethods();
}


More information about the Digitalmars-d-learn mailing list