Q: Populating a structure with RTTI
BLS
nanali at nospam-wanadoo.fr
Mon Jun 11 03:05:08 PDT 2007
Hi Myron,
I am also thinking about this problem for quit a while.
Maybe you can use the D Mixin feature and compile time manipulation of
strings to create an database-table adequate structure :
template GenStruct(char[] Name, char[] M1)
{
const char[] GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }";
}
mixin(GenStruct!("Foo", "bar"));
Just an idea, Bjoern
Myron Alexander schrieb:
> 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