Metaprogramming with traits

rikki cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 15 08:09:35 PDT 2016


On 16/09/2016 3:07 AM, Ram_B wrote:
> How i can get fields of derived classes in runtime? This not works
>
> import std.traits;
> import std.experimental.logger;
>
>
> class A {
>     int a,b;
>     this(){}
>     void fields(){
>         log(FieldNameTuple!this);
>     }
> }
>
> class B : A{
>     int c;
>     this(){}
> }
>
> void main(){
>     B b = new B();
>     b.fields();
> }

A few weeks ago I wrote an article for TWID that covers this very subject.
Sadly because of a bug in dmd it doesn't work for all cases perfectly.

http://arsdnet.net/this-week-in-d/2016-aug-28.html


More information about the Digitalmars-d-learn mailing list