November 07, 2006 Re: Static foreach. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:eiolhg$21va$1@digitaldaemon.com... > This looks to me like a good way to do reflection. Imagine that each variable had a property called "members" which returned the tuple of all of the members. Then dumping all of the members of a struct would be as simple as: > > foreach(member; this.members) > writefln(member); > > Of course, if tuples were extended to include a "name" field, which was the name that was used to access the field, then we'd have everything: > > foreach(member; this.members) > writefln(member.name," ",member); > > Of course, if we can do this, then we can do almost everything needed for reflection (especially if we are able to take the address of one element of a tuple, and that works out being the pointer to the member in the struct). > > Tuples aren't there yet, but they're close. Wooooo! That's so tantalizing. |
Copyright © 1999-2021 by the D Language Foundation