December 16, 2006 [Issue XXX] ToBeFiled: rules for assigning to complex types are too strict | ||||
---|---|---|---|---|
| ||||
[I'll file this for real once Bugzilla is back] //You can assign ints and floats and doubles to a double with no //problem. Even arrays work. void test1() { // All ok double a = 0; double b = 0.0; double c = 0.0f; double[] d = [0]; double[] e = [0.0]; double[] f = [0.0f]; } //But there's very little that can be assigned to a cdouble: void test2() { // All errors cdouble a = 0; cdouble b = 0i; cdouble c = 0.0; cdouble d = 0.0f; cdouble e = 0.0fi; cdouble[] f = [0]; } //Yet, it is ok to add many things to a cdouble. void test3() { // All ok: cdouble a = 0+0i; cdouble b = a + 0; cdouble c = a + 0i; cdouble d = a + 0.0; cdouble e = a + 0.0f; cdouble f = a + 0.0fi; } I don't see any good reason for this strictness. I suspsect nobody's complained simply because few current users actually touch complex types. Real world impact: In writing a generic BLAS/LAPACK-backed nd-array class I find that many of my generic test cases have to contain sillyness like: T z = cast(T)0; A = [[z+ 5, z+ 1, z+ 2], [z+ 3, z+ 4, z+ 5], [z+ 6, z+ 7, z+ 8]]; x = [z+ 1, z+ 2, z+ 3]; b = mult(A,x); just to handle complex types without generating compiler errors. |
Copyright © 1999-2021 by the D Language Foundation