digitalmars.D - The type of an element-wise arithmetic expression
- Eduardo Cavazos (22/22) Aug 21 2010 Hello,
- bearophile (8/19) Aug 21 2010 I am not sure this code is supported. I think that currently the right w...
Hello, This program: ---------------------------------------------------------------------- import std.stdio ; void f0 ( double [2] a ) { writeln ( a ) ; } void main () { double [2] a = [ 1.0 , 2.0 ] ; double [2] b = [ 3.0 , 4.0 ] ; f0 ( a[] - b[] ) ; } ---------------------------------------------------------------------- produces an error: $ rdmd array_wise_a.d array_wise_a.d(11): Error: function array_wise_a.f0 (double[2u] a) is not callable using argument types (double[]) array_wise_a.d(11): Error: cannot implicitly convert expression (a[] - b[]) of type double[] to double[2u] Since the sub-expressions a[] and b[] are each of type double[2], I would expect the the type of a[]-b[] to also be of double[2], and thus compatible with f0. Ed
Aug 21 2010
Eduardo Cavazos:import std.stdio ; void f0 ( double [2] a ) { writeln ( a ) ; } void main () { double [2] a = [ 1.0 , 2.0 ] ; double [2] b = [ 3.0 , 4.0 ] ; f0 ( a[] - b[] ) ; }I am not sure this code is supported. I think that currently the right way to use array ops is to give a wide enough as lvalue. But note this syntax can't be used (I have a bug report on this too) (the usage of [] has to become obligatory): double[2] c[] = a[] - b[]; So you need to use something like: double[2] c = void; c[] = a[] - b[]; Bye, bearophile
Aug 21 2010