template this and traits getOverloads issue.
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Nov 20 06:49:24 PST 2015
On Friday, 20 November 2015 at 14:01:13 UTC, BBasile wrote:
> everything that can be done to avoid the compilations errors
> will also prevent "bar" to be written in the output (because a
> B will never be analyzed). The "only" fix I see is like in the
> stack overflow answer: statically check if the mixin methods
> are already there and remix the mixin in each descendant, so
> that the getOverloads traits works on the right 'this'.
Did you try using a template this parameter like I said in my
comment?
import std.stdio;
mixin template Bug()
{
import std.traits;
void bug(this T)()
{
T this_ = cast(T) this;
foreach(member; __traits(allMembers, T))
foreach(idx, overload; __traits(getOverloads, T,
member))
{
auto dg = &(__traits(getOverloads, this_,
member)[idx]);
writeln(T.stringof, ".", member, " ",
typeof(dg).stringof);
}
}
}
class A
{
mixin Bug;
this(){bug;}
void foo(){}
}
class B: A
{
void bar(){}
void bar(uint a){}
this(){this.bug;}
}
void main(){
new A;
new B;
}
There's a couple quirks in there, but I think you'll find the
output shows what you want to see.
More information about the Digitalmars-d-learn
mailing list