Re: Implicit conversion between structs?

2011-10-31 Thread Steve Teale
OK, I stand corrected Steve

Re: Implicit conversion between structs?

2011-10-31 Thread Andrei Alexandrescu
On 10/31/11 12:39 PM, Steve Teale wrote: On Mon, 31 Oct 2011 07:58:11 -0500, Andrei Alexandrescu wrote: On 10/31/11 4:43 AM, Steve Teale wrote: Is there a way to do this. For example if I have struct A { int a, b, c; } struct B { int p, q, r, s; this(A a) { p = a.a; q = a.b; r = a.c

Re: Implicit conversion between structs?

2011-10-31 Thread Ali Çehreli
On Mon, 31 Oct 2011 17:39:57 +, Steve Teale wrote: > On Mon, 31 Oct 2011 07:58:11 -0500, Andrei Alexandrescu wrote: > >> On 10/31/11 4:43 AM, Steve Teale wrote: >>> Is there a way to do this. For example if I have >>> >>> struct A { int a, b, c; } >>> struct B >>> { >>> int p, q, r, s; >>

Re: Implicit conversion between structs?

2011-10-31 Thread bearophile
Steve Teale: > But if B is not mine to mess with? > > The two structs have a common type prefix. and D guarantees that there > are predictable values for the remainder of the larger one, so the > compiler could presumably figure it out. (Easy for me to say) Looks like a job for StructuralCast!

Re: Implicit conversion between structs?

2011-10-31 Thread Steve Teale
On Mon, 31 Oct 2011 07:58:11 -0500, Andrei Alexandrescu wrote: > On 10/31/11 4:43 AM, Steve Teale wrote: >> Is there a way to do this. For example if I have >> >> struct A { int a, b, c; } >> struct B >> { >> int p, q, r, s; >> this(A a) { p = a.a; q = a.b; r = a.c; } >> } >> >> A a; >> B

Re: Implicit conversion between structs?

2011-10-31 Thread Andrei Alexandrescu
On 10/31/11 4:43 AM, Steve Teale wrote: Is there a way to do this. For example if I have struct A { int a, b, c; } struct B { int p, q, r, s; this(A a) { p = a.a; q = a.b; r = a.c; } } A a; B b; b = a; Use opAssign? Andrei

Implicit conversion between structs?

2011-10-31 Thread Steve Teale
Is there a way to do this. For example if I have struct A { int a, b, c; } struct B { int p, q, r, s; this(A a) { p = a.a; q = a.b; r = a.c; } } A a; B b; b = a;