digitalmars.D.learn - get literal symbol name without base class/struct as string
give structs like this:
struct A
{
int a = 10;
string s = "haha";
}
struct B
{
A aDetails;
}
I'd like to do this and store that symbol name as string (my goal
is store the member name);
string memberName = magic(B.aDetails.s);
writeln(memberName); // otuput "aDetails.s"
how can I do that?
closet I got was:
template nameof(alias S) {
import std.array : split, join;
import std.traits;
pragma(msg, fullyQualifiedName!S);
pragma(msg, "stringof = " ~ S.stringof);
enum parts = fullyQualifiedName!S.split(".");
enum nameof = parts[1 .. $].join(".");
}
but neither fullyQualifiedName nor stringof give the symbol in
the way I need.
Apr 17 2018
On Tuesday, 17 April 2018 at 21:45:45 UTC, Dr.No wrote:
give structs like this:
struct A
{
int a = 10;
string s = "haha";
}
struct B
{
A aDetails;
}
but neither fullyQualifiedName nor stringof give the symbol in
the way I need.
I'd hint you towards
import std.traits;
pragma(msg, FieldNameTuple!B);
pragma(msg, FieldNameTuple!(Fields!B[0]));
Apr 19 2018








Timoses <timosesu gmail.com>