Re: to!() conversion between objects

2011-10-21 Thread Gor Gyolchanyan
That would be great! that ides evaluates to: --boilerplate; On Thu, Oct 20, 2011 at 7:02 PM, Andrei Alexandrescu seewebsiteforem...@erdani.org wrote: On 10/20/11 6:53 AM, kenji hara wrote: I think std.conv.to should provide the *safe natural conversion*. Field-to-field conversion seems not

Re: to!() conversion between objects

2011-10-20 Thread Piotr Szturmaj
Robert Jacques wrote: On Wed, 19 Oct 2011 14:16:31 -0400, Piotr Szturmaj bncr...@jadamspam.pl wrote: bearophile wrote: Piotr Szturmaj: I have written a simple conversion template for tuples, structs and classes: Do you have some use case to show me? class C { int i; string s; } struct S

Re: to!() conversion between objects

2011-10-20 Thread Piotr Szturmaj
bearophile wrote: Piotr Szturmaj: Do you have some use case to show me? class C { int i; string s; } struct S { string s; float f; } auto c = to!C(S(5, 2.5f)); assert(c.i == 5 c.s == 2.5); This is an usage example, it isn't an use case. And it looks a bit messy.

Re: to!() conversion between objects

2011-10-20 Thread bearophile
Piotr Szturmaj: -- for CSV: alias Tuple!(int, string, int) IdNameAge; foreach (csvLine; csvFile.byCSVLine) { auto line = to!IdNameAge(splitter(csvLine, ';')); // line here is a tuple converted from runtime csv fields } See here the answer 23 by Andrei Alexandrescu to a

Re: to!() conversion between objects

2011-10-20 Thread Piotr Szturmaj
bearophile wrote: Piotr Szturmaj: -- for CSV: alias Tuple!(int, string, int) IdNameAge; foreach (csvLine; csvFile.byCSVLine) { auto line = to!IdNameAge(splitter(csvLine, ';')); // line here is a tuple converted from runtime csv fields } See here the answer 23 by Andrei

Re: to!() conversion between objects

2011-10-20 Thread kenji hara
2011/10/20 Piotr Szturmaj bncr...@jadamspam.pl: Robert Jacques wrote: On Wed, 19 Oct 2011 14:16:31 -0400, Piotr Szturmaj bncr...@jadamspam.pl wrote: bearophile wrote: Piotr Szturmaj: I have written a simple conversion template for tuples, structs and classes: Do you have some use case

Re: to!() conversion between objects

2011-10-20 Thread Andrei Alexandrescu
On 10/20/11 6:53 AM, kenji hara wrote: I think std.conv.to should provide the *safe natural conversion*. Field-to-field conversion seems not natural, and it is called 'Structural conversion'. I agree. We could, however, add std.conv.structuralCast. Andrei

to!() conversion between objects

2011-10-19 Thread Piotr Szturmaj
I have written a simple conversion template for tuples, structs and classes: https://gist.github.com/1299046 The problem is that it may conflict with to!Class1(Class2) template. This template does dynamic cast and throw exception when the target is null and source is non null. Why implement

Re: to!() conversion between objects

2011-10-19 Thread bearophile
Piotr Szturmaj: I have written a simple conversion template for tuples, structs and classes: Do you have some use case to show me? Bye, bearophile

Re: to!() conversion between objects

2011-10-19 Thread Piotr Szturmaj
bearophile wrote: Piotr Szturmaj: I have written a simple conversion template for tuples, structs and classes: Do you have some use case to show me? class C { int i; string s; } struct S { string s; float f; } auto c = to!C(S(5, 2.5f)); assert(c.i == 5 c.s == 2.5);

Re: to!() conversion between objects

2011-10-19 Thread Piotr Szturmaj
Piotr Szturmaj: I have written a simple conversion template for tuples, structs and classes: This is only the part to complement universal range/array to tuple/struct/class conversion. It may be useful in mapping runtime fields like database rows or CSV lines onto objects. I think Phobos

Re: to!() conversion between objects

2011-10-19 Thread Jonathan M Davis
On Wednesday, October 19, 2011 19:47:55 Piotr Szturmaj wrote: I have written a simple conversion template for tuples, structs and classes: https://gist.github.com/1299046 The problem is that it may conflict with to!Class1(Class2) template. This template does dynamic cast and throw

Re: to!() conversion between objects

2011-10-19 Thread Robert Jacques
On Wed, 19 Oct 2011 14:31:20 -0400, Piotr Szturmaj bncr...@jadamspam.pl wrote: Piotr Szturmaj: I have written a simple conversion template for tuples, structs and classes: This is only the part to complement universal range/array to tuple/struct/class conversion. It may be useful in mapping

Re: to!() conversion between objects

2011-10-19 Thread Robert Jacques
On Wed, 19 Oct 2011 14:16:31 -0400, Piotr Szturmaj bncr...@jadamspam.pl wrote: bearophile wrote: Piotr Szturmaj: I have written a simple conversion template for tuples, structs and classes: Do you have some use case to show me? class C { int i; string s; } struct S {

Re: to!() conversion between objects

2011-10-19 Thread bearophile
Piotr Szturmaj: Do you have some use case to show me? class C { int i; string s; } struct S { string s; float f; } auto c = to!C(S(5, 2.5f)); assert(c.i == 5 c.s == 2.5); This is an usage example, it isn't an use case. And it looks a bit messy. Bye,