Getting the current module as a symbol
Vladimir Panteleev via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Apr 12 22:30:27 PDT 2016
On Tuesday, 12 April 2016 at 13:44:07 UTC, Mithun Hunsur wrote:
> Hi all,
>
> I'm looking for the equivalent of `typeof(this)` in module
> scope (so that it gets the current module). My use-case is
> iterating over the members of the module - right now I'm doing
>
> `mixin(iterateOverModule!(module.name.here));`
>
> but in the interests of keeping the code simple to maintain,
> I'd like to be able to get the current module automatically.
>
> Is this possible? A cursory Google search didn't turn up
> anything, and `this` has no meaning in module scope.
Have you tried __traits(parent, someTopLevelSymbol)?
Walking the __traits(parent) chain should get you to a module
either way, I think.
More information about the Digitalmars-d-learn
mailing list