Is __traits(derivedMembers) supposed to return mangled names?

Denis Koroskin 2korden at gmail.com
Fri Dec 5 13:22:19 PST 2008


On Sat, 06 Dec 2008 00:13:40 +0300, Mike Hearn <mike at plan99.net> wrote:

> The language spec is ambiguous, and DMD can apparently do either. This  
> program prints
>
> [a __T3TagS23_D11smartstruct4Test1aiVi1Z b  
> __T3TagS24_D11smartstruct4Test1bAaVi2Z]
>
> Note: this is a lame-ass hack around the lack of real metadata  
> attributes in D2. It'd be nice if the real thing was supported.
>
>
> import std.stdio;
>
> template Tag(alias m, int i) {
>   mixin("const int tag_" ~ m.stringof ~ " = " ~ i.stringof ~ ";");
> };
>
> class Test {
>   int    a;   mixin Tag!(a, 1);
>   char[] b;   mixin Tag!(b, 2);
> };
>
> int main(char[][] args) {
>   writefln(__traits(derivedMembers, Test));
>   return 0;
> }
>

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.



More information about the Digitalmars-d mailing list