digitalmars.D.learn - Is there a way to get the list of names of a class' member variables?
- Jonathan M Davis (6/6) Jul 04 2010 MemberFunctionsTuple() from std.traits will return the list of names of ...
- Simen kjaeraas (7/16) Jul 04 2010 __traits[1] is your friend in these matters.
- Simen kjaeraas (7/20) Jul 04 2010 If you prefer the temmplated way, here's a FieldNameTuple template:
- Philippe Sigaud (5/10) Jul 04 2010 Somehting I discovered today: it works for module names, also:
MemberFunctionsTuple() from std.traits will return the list of names of member function, and FieldTypeTuple from std.traits will return the list of the _types_ of the member variables. But I don't see a function that returns the list of the _names_ of the member variables. Am I just blind, or does such a function not currently exist? - Jonathan M Davis
Jul 04 2010
Jonathan M Davis <jmdavisprog gmail.com> wrote:MemberFunctionsTuple() from std.traits will return the list of names of member function, and FieldTypeTuple from std.traits will return the list of the _types_ of the member variables. But I don't see a function that returns the list of the _names_ of the member variables. Am I just blind, or does such a function not currently exist?__traits[1] is your friend in these matters. __traits( allMembers, Foo ) returns a tuple of string literals, each of which corresponds to a member of Foo. [1] http://www.digitalmars.com/d/2.0/traits.html -- Simen
Jul 04 2010
Simen kjaeraas <simen.kjaras gmail.com> wrote:Jonathan M Davis <jmdavisprog gmail.com> wrote:If you prefer the temmplated way, here's a FieldNameTuple template: template FieldNameTuple( T ) { enum FieldNameTuple = __traits( allMembers, T ); } -- SimenMemberFunctionsTuple() from std.traits will return the list of names of member function, and FieldTypeTuple from std.traits will return the list of the _types_ of the member variables. But I don't see a function that returns the list of the _names_ of the member variables. Am I just blind, or does such a function not currently exist?__traits[1] is your friend in these matters. __traits( allMembers, Foo ) returns a tuple of string literals, each of which corresponds to a member of Foo.
Jul 04 2010
On Sun, Jul 4, 2010 at 12:55, Simen kjaeraas <simen.kjaras gmail.com> wrote:__traits[1] is your friend in these matters.Somehting I discovered today: it works for module names, also: auto ioMembers = __traits(allMembers, std.stdio); It also contains the unittests... Hmm, I wonder what one can do with that. Philippe__traits( allMembers, Foo ) returns a tuple of string literals, each of which corresponds to a member of Foo.
Jul 04 2010