Q: Populating a structure with RTTI

Myron Alexander someone at somewhere.com
Sun Jun 10 19:18:09 PDT 2007


Hello.

Is it possible to populate a struct using RTTI?

Example:

Say I have a struct as such:

struct Example {
    int    x;
    int    y;
    char[] z;
}

and I want to create and populate the structure from a function:

T populate(T) () {
   T t;
   t.field[0] = 1;
   t.field[1] = 2;
   t.field[2] = "testing";
   return t;
}

void main() {
   auto x = populate!(Example)();
}

Is this possible? If so, what is the syntax?

Thanks ahead,

Myron.


More information about the Digitalmars-d-learn mailing list