Static foreach.
Russ Lewis
spamhole-2001-07-16 at deming-os.org
Mon Nov 6 16:55:36 PST 2006
Jarrett Billingsley wrote:
> void print(T...)(T args)
> {
> foreach(arg; args)
> writef(arg);
>
> writefln();
> }
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.
More information about the Digitalmars-d
mailing list