On Friday, 12 July 2013 at 11:28:19 UTC, Jacob Carlborg wrote:
On 2013-07-12 09:25, JS wrote:
BTW, the error is
testmodule.d(14): Error: undefined identifier main
Where does "main" come from?
which suggests that the template can't find the module. I can
import the
module and it will work fine but this seems a bit circular. I
will try
and mixin the module to solve my original problem but still
need to
figure out how to handle overloads.
Try this:
1. Iterate over all members
2. Run __traits(getOverloads) for each member
3. Iterate all overloads
3. Run __traits(isFinalFunction) for each overload
http://dlang.org/traits.html#getOverloads
http://dlang.org/traits.html#allMembers
http://dlang.org/traits.html#derivedMembers
main is the main module. I've tried your method already but
couldn't get it to work. I think it is ultimately flawed because
one still needs to compare against the full definition.
I was able to get it to work in any case by modifying std.traits.
It has a more advanced GetOverloads template that ignores static
functions. I included it to ignore final functions also... this
might be a bug in the code as I'm sure if it wants to ignore
static it probably should ignore finals.
template isMethod(alias f)
{
static if (is(typeof(&f) F == F*) && is(F ==
function))
{
enum isMethod = !__traits(isStaticFunction,
f) && !__traits(isFinalFunction, f);
}
else
enum isMethod = false;
}