get only user-defined members

Marc jckj33 at gmail.com
Sat Dec 16 15:28:46 UTC 2017


On Saturday, 16 December 2017 at 07:23:38 UTC, Jonathan M Davis 
wrote:
> On Saturday, December 16, 2017 04:01:10 Marc via 
> Digitalmars-d-learn wrote:
>> how do I from class:
>> > class Person {
>> >
>> >  string name;
>> >  int age;
>> >
>> > }
>>
>> do:
>> > auto c = [__traits(allMembers, Person)];
>>
>> then return only ["name", "age"] rather ["name, "age", "ctor", 
>> "toString" ... ]?
>
> Try __traits(derivedMembers, Person).
>
> https://dlang.org/spec/traits.html#derivedMembers
>
> Depending on what you want though, it's not all that uncommon 
> to use a variety of traits to filter the list down to whatever 
> it is that you actually want. std.traits and std.meta are your 
> friends in addition to __traits.
>
> - Jonathan M Davis

It derivedMembers worked but I didn't understand how so. It 
returned the proper array ["name", "age", "this"] but how are 
them derived? or it's D's design that every class is implicitily 
derived from a "main objet"?
Thanks for your suggeston on std.traits and std.meta, I didn't 
know about the last one.


More information about the Digitalmars-d-learn mailing list