On Wednesday, 13 April 2016 at 16:58:34 UTC, Vladimir Panteleev wrote:
On Wednesday, 13 April 2016 at 11:36:07 UTC, Mithun Hunsur wrote:
Yeah, that also works; you have to define a symbol (if you don't have one you can already use) in order to get to it, so it's a little wasteful. Still useful to know, though!

No, it's not necessary. You should be able to walk the chain of __traits(parent) by starting with a local symbol, e.g. a lambda predicate.

Have a look at std.traits.moduleName which does most of the work.

Aha! That is a _very_ clever trick. :) For everyone else:

__traits(parent, {});

The {} is a lambda predicate instantiated in the current scope (i.e. module scope); getting the parent of that gets you the module. If you wanted to generalise that, you could walk up the parent chain like Vladimir says - but this is perfect for my uses. Thanks again!

Reply via email to