Array operation with boolean operator

Andrea Fontana nospam at example.com
Thu Mar 14 10:45:21 PDT 2013


On Thursday, 14 March 2013 at 13:58:45 UTC, n00b wrote:
> I tried to use a boolean operator for an array operation :
>
> a[] = b[] < c[];
>
> It compiles but seems to only fill a[] with the result of b[0] 
> < c[0].
> Is there any "rational" reason to that?

Yes i think there is a rational reason. Check this:

int a[] = [1,0,0];
int b[] = [0,1,0];
int c[] = [1,1,0];

bool ab = a[] < b[]; // False.  a[0] > b[0]
bool ac = a[] < c[]; // True.  a[0] == c[0] but a[1] < c[1];

writeln(ab);
writeln(ac);
c[] = ab; // <-- assign!

You see? Your code do this:

a[] = (b[] < c[]);


More information about the Digitalmars-d-learn mailing list