www.digitalmars.com         C & C++   DMDScript  

D - operator+ and arrays

reply "Ben Hinkle" <bhinkle4 juno.com> writes:
In the doc for the + operator it says:

"For the + operator, if both operands are arrays of a compatible type, the
resulting type is an array of that compatible type, and the resulting value
is the concatenation of the two arrays."

Why support this when there is the ~ operator? I would expect array + to try
to add element-wise - as should all artithmetic operations. Or it should
error.

-Ben
Jan 27 2004
parent reply "Walter" <walter digitalmars.com> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:bv5plg$1s6a$1 digitaldaemon.com...
 In the doc for the + operator it says:

 "For the + operator, if both operands are arrays of a compatible type, the
 resulting type is an array of that compatible type, and the resulting
value
 is the concatenation of the two arrays."
The doc is wrong. I'll fix it.
 Why support this when there is the ~ operator? I would expect array + to
try
 to add element-wise - as should all artithmetic operations. Or it should
 error.

 -Ben
Jan 27 2004
parent "Ben Hinkle" <bhinkle4 juno.com> writes:
"Walter" <walter digitalmars.com> wrote in message
news:bv7jl6$1u97$2 digitaldaemon.com...
 "Ben Hinkle" <bhinkle4 juno.com> wrote in message
 news:bv5plg$1s6a$1 digitaldaemon.com...
 In the doc for the + operator it says:

 "For the + operator, if both operands are arrays of a compatible type,
the
 resulting type is an array of that compatible type, and the resulting
value
 is the concatenation of the two arrays."
The doc is wrong. I'll fix it.
OK. I just tried it and it errors. Adding vectorized arithmentic ala Fortran, S or MATLAB would, I think, be really great but I can see how it could wait. The biggest problem with vectorized math in C/C++ is the memory management since the result array is implicitly allocated - but that is a non-issue with GC.
 Why support this when there is the ~ operator? I would expect array + to
try
 to add element-wise - as should all artithmetic operations. Or it should
 error.

 -Ben
Jan 28 2004