reference to 'self' inside a function
Rob T
rob at ucora.com
Tue Sep 18 14:21:17 PDT 2012
On Tuesday, 18 September 2012 at 19:57:05 UTC, Ben Davis wrote:
> Wild stab in the dark, but would something like this work:
>
> void myfunction() {
> int dummy;
> auto self = __traits(parent, dummy);
> }
>
> though it would be better if something like __traits(enclosing)
> were supported.
>
This hack will generate the enclosing function name
void function x()
{
int dummy;
auto funcname = __traits( identifier, __traits( parent, dummy )
);
writefln( funcname );
}
Obviously the above solution is not reasonable, esp for a
language that attempts to provide good reflection abilities.
What would work considerably better is something ike this
void function x()
{
writeln(self.symbolname);
}
More information about the Digitalmars-d
mailing list