Array operation with boolean operator

bearophile bearophileHUGS at lycos.com
Thu Mar 14 18:19:32 PDT 2013


Marco Leise:

> This is "just" a syntax ambiguity. a[] takes the complete
> slice of the array 'a'. And a dynamic array in D is a slice.
> So if you use a or a[] in an expression doesn't make much of a
> difference.

Yet in D the only accepted syntax to perform a vector op sum is 
to use add square brackets both operands:


void main() {
     auto a = new int[5];
     auto b = new int[5];
     auto c = new int[5];
     c[] = a[] + b[]; // OK
     c[] = a + b; // Error: invalid array operation
     c[] = a[] + b; // Error: invalid array operation
     c[] = a + b[]; // Error: invalid array operation
}


Bye,
bearophile


More information about the Digitalmars-d-learn mailing list