Is __traits(derivedMembers) supposed to return mangled names?

Mike Hearn mike at plan99.net
Fri Dec 5 13:43:46 PST 2008


> Yeah, I'm using the same hack (i.e. defining private static const members)  
> to denote some members characteristics, e.g. whether a member is  
> serializable, its value is written to log etc.

Is the code open source? I was intending to put together some kind of better integrated protobufs equivalent, ie with the same concept of optional/required tagged fields and efficient serialization, but type safe and better integrated with the language.

Another oddity of __traits, this prints

dump!
a
__T3TagS23_D11smartstruct4Test1aiVi1Z
b
__T3TagS24_D11smartstruct4Test1bAaVi2Z
__T11SmartStructZ

So dump() isn't considered a member, but the name of the mixin does appear! 



import std.stdio;

template Tag(alias m, int i) {
  mixin("const int tag_" ~ m.stringof ~ " = " ~ i.stringof ~ ";");
};

template SmartStruct() {
  void dump() {
    writefln("dump!");
  }
};

struct Test {
  int    a;   mixin Tag!(a, 1);
  char[] b;   mixin Tag!(b, 2);

  mixin SmartStruct;
};

int main(char[][] args) {
  Test t;
  t.dump();

  foreach (member; __traits(allMembers, Test)) {
    writefln(member);
  }
  
  return 0;
}




More information about the Digitalmars-d mailing list