Michiel Helvensteijn wrote:
* Operator overloading (no fine control over comparison operators,
 > fixed commutativity,

This is deliberate. Operator overloading should be restricted to
implementing arithmetic like operations on objects, not completely
different things like what iostreams, Spirit and Boost::regex do.
Arithmetic like operations like matrix multiplication (which is not
commutative)?
I believe this is completely controllable with D.

Not if commutativity of the * operator is fixed. The documentation states
that * is commutative, which in fact for integers it is. So if I overload *
for matrices, for all the guarantees the docs give me, a D compiler might
choose to swap the operands around (perhaps to get some memory alignment
advantage), and the returned matrix would be incorrect.

That's not what the documentation means. * is only 'default commutative'. If a.opMul(b) is defined, by default you get b * a == a*b. To prevent this behaviour, you just need to define a.opMul_r(b), or b.opMul(a).

(The documenation could be a bit clearer on this).

Reply via email to