Deduplicating template reflection code

Johannes Pfau via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 14 01:24:00 PDT 2017


I've got this code duplicated in quite some functions:

---------------------
foreach (member; __traits(derivedMembers, API))
{
    // Guards against private members
    static if (__traits(compiles, __traits(getMember, API, member)))
    {
        static if (isSomeFunction!(__traits(getMember, API, member))
                && !hasUDA!(__traits(getMember, API, member), IgnoreUDA)
                && !isSpecialFunction!member)
        {
            alias overloads = MemberFunctionsTuple!(API, member);

            foreach (MethodType; overloads)
            {
		// function dependent code here
            }
        }
    }
}
--------------------

What's the idiomatic way to refactor / reuse this code fragment?

-- Johannes



More information about the Digitalmars-d-learn mailing list