Identifier hierarchy

Simen Kjærås simen.kjaras at gmail.com
Mon Jun 11 13:19:17 UTC 2018


On Monday, 11 June 2018 at 12:59:01 UTC, Mike Franklin wrote:
> On Monday, 11 June 2018 at 12:38:33 UTC, Luís Marques wrote:
>> Just to check. If you have a piece of code like "foo.bar.baz", 
>> you can get the full hierarchy, for instance with stringof:
>>
>>
>>      static assert(foo.bar.baz.stringof == "foo.bar.bar");
>>
>
> Are you looking for this: 
> https://dlang.org/phobos/std_traits.html#fullyQualifiedName ?

That only works for modules and types - Luís mentioned that 
__traits(identifier) only returns the type, not the identifier. 
Consider:

module foo;
import std.traits;

struct S { int n; }

unittest {
     S s;
     // Prints "s.n"
     pragma(msg, s.n.stringof);
     // Prints "foo.S.n".
     pragma(msg, fullyQualifiedName!(s.n));
}

As for getting the name s.n inside a template, I don't think 
that's currently possible.

--
   Simen


More information about the Digitalmars-d mailing list