void main() { float[] f; double[] d; f[] = d[]; } test9.d(4): Error: cannot implicitly convert expression (d[]) of type double[] to const(float[])
Why? And only double->float? int->long too?
(In reply to comment #1) > Why? And only double->float? int->long too? Of course int -> long should work, too. Same with anything where implicit conversions are allowed. It's just that double -> float is the first case I stumbled upon.
What is the compelling rationale for this? Is there a use case that shows it? (Also marked as an enhancement request, as it is not a bug.)
The compelling rationale is consistency. I can assign the elements of a float[] to a double[] one-by-one, so why not with array-wise operations?
Please show one or more use case. Do you want it to be like a reinterpret cast? Currently this works: void main() { ushort[4] a = [1, 2, 3, 4]; uint[2] b = cast(uint[2])a; assert(b == [131073, 262147]); } Mixing reinterpret cast with conversion casts is a bad design.
No. The idea is that it should work exactly the same as if I'd written out the loop manually: arrayOfFloats[] = arrayOfDoubles[] // Equivalent to: foreach(i, elem; arrayOfDoubles) { arrayOfFloats[i] = elem; }
(In reply to comment #4) > The compelling rationale is consistency. I can assign the elements of a > float[] to a double[] one-by-one, so why not with array-wise operations? Actually, allowing this would introduce a huge inconsistency. The existing rule is simple and consistent: you can't mix sizes. Suppose this were allowed. Then what about: float [] a; double [] b; b[]= a[]*3.7; So for the sake of consistency you are forced to support a huge number of operations which are very complicated to implement, and which perform so poorly, that they generally indicate a bug in the users code. Consistency is a very, very strong argument against implementing this. There possibly could be arguments for supporting it as a special case; but they would need to be very strong, since would involve introducing an inconsistency.
I'll WONTFIX this terrible proposal in a try to stop it magically affect dmd to such a degree as Issue 11470.