loop through specific class members

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Jan 20 11:26:58 PST 2009


On Tue, Jan 20, 2009 at 2:13 PM, Trass3r <mrmocool at gmx.de> wrote:
> Yeah, __traits works quite well to get the function names, but I still can't
> manage to get the corresponding function object to pass it to
> ParameterTypeTuple (for checking the parameters for correctness).

Ah, that's what __traits(getMember) is for.  You pass it an
object/class and a string of the member name, and it gives you what it
corresponds to.

> Tried using ClassInfo's getMembers function but that apparently doesn't
> work.
>
> Base base = new Base;
> auto members = __traits(allMembers, typeof(base));
> foreach(m; members)
>        writefln(base.classinfo.getMembers(m).length);
>
> gives 0 for every member :(

I think that's actually a bug.  DMD doesn't generate that info for
some reason.  I think LDC does.


More information about the Digitalmars-d-learn mailing list