On Monday, 11 June 2018 at 13:19:17 UTC, Simen Kjærås wrote:
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
the FQN is working here but i find the first message a bit
confuse. Not sure if this small runnable represents the issue ?
---
module runnable;
import std.stdio, std.traits;
struct foo { struct bar { static int baz;} }
template Test(alias arg)
{
pragma(msg, fullyQualifiedName!arg);
}
void main()
{
alias t = Test!(foo.bar.baz); // runnable.foo.bar.baz
}
---