Get parent function of nested delegate

Inkrementator invalid at invalid.org
Sun Feb 16 15:19:25 UTC 2025


On Sunday, 16 February 2025 at 07:38:09 UTC, Anonymouse wrote:
> How can I make this work?

As a workaround, you can define a useless symbol and get the 
parent of that.
```
module foo;

void bar(string s, int i)
{
     assert(__FUNCTION__ == "foo.bar");
     alias parentModule = __traits(parent, mixin(__FUNCTION__));
     assert(is(parentModule == module));

     void dg()
     {
         assert(__FUNCTION__ == "foo.bar.dg");
	enum n = 0;
         alias parentFunction = __traits(parent, __traits(parent, 
n));
	pragma(msg, __traits(identifier, parentFunction)); // bar
	pragma(msg, __traits(identifier, __traits(parent, n))); // dg

     }
}

void main() {}
```


More information about the Digitalmars-d-learn mailing list