Re: Associative array to Struct at compile time

2014-07-25 Thread BlackEdder via Digitalmars-d-learn
On Friday, 25 July 2014 at 15:48:54 UTC, John Colvin wrote: On Friday, 25 July 2014 at 15:25:43 UTC, BlackEdder wrote: Is it possible to automatically convert an associative array to a struct? Basically I want to do the following (for any struct). struct A { double x = 1; } double[string]

Re: Associative array to Struct at compile time

2014-07-25 Thread John Colvin via Digitalmars-d-learn
On Friday, 25 July 2014 at 15:25:43 UTC, BlackEdder wrote: Is it possible to automatically convert an associative array to a struct? Basically I want to do the following (for any struct). struct A { double x = 1; } double[string] aa = ["x":1]; auto a = toStruct!A( aa ); I've been trying

Re: Associative array to Struct at compile time

2014-07-25 Thread bearophile via Digitalmars-d-learn
BlackEdder: Is this possible at all? I think it's possible, as long as your associative array contents are known at compile-time. You can write a function that given the associative array returns a string that mixed-in defines the struct. And then you can define a toStruct template. Bye,