tuples and names

Kevin Bealer kevinbealer at gmail.com
Thu Nov 16 15:14:22 PST 2006


Sorry - that should be:
      foreach(int i, auto A; z.tupleof) {
          writefln("<%s>%s</%s>", name[i], A, name[i]);
      }

I'm thinking that .fieldnamesof would return a tuple of char[] objects, and maybe
there would be a .methodnames of that returns method names (or signatures?) to
allow searching by name for delegate binding purposes.

One application of this is serialization.  Another might be something like the
"xpath" functionality of Java's XML support, i.e. I could have a complex series of
nested structures and do something like this:

struct Foo {
...
  Bar b;
}

struct Bar {
...
  Car c;
}

struct Car {
...
  int d;
}

char[] name = "Foo.b.c.d";
int * d_found;
Foo document;

// Set d_found to a pointer into Foo.b.c.d:
FindStructPath!(document, name, d_found);

If we had the field names, this kind of FindStructPath!() template could be written.

For a program like a web browser, being able to specify paths into document
objects or similar could lead to powerful configurability.

I also wanted to say that I've been away for a bit but the rate of progress here
is still really amazing.  The rise in TIOBE rank (almost every language with a
higher rank is a household name), version 1.0 in January already, and the language
features and library innovations still keep pouring in!

Kevin



More information about the Digitalmars-d mailing list