Operator overloading -- lets collect some use cases

Bill Baxter wbaxter at gmail.com
Sun Dec 28 23:46:09 PST 2008

On Mon, Dec 29, 2008 at 1:50 AM, Don <nospam at nospam.com> wrote:
> There's been some interesting discussion about operator overloading over the
> past six months, but to take the next step, I think we need to ground it in
> reality. What are the use cases?
> I think that D's existing opCmp() takes care of the plethora of trivial
> cases where <, >= etc are overloaded. It's the cases where the arithmetic
> and logical operations are overloaded that are particularly interesting to
> me.
> The following mathematical cases immediately spring to mind:
> * complex numbers
> * quaternions (interesting since * is anti-commutative, a*b = -b*a)
> * vectors
> * matrices
> * tensors
> * bigint operations (including bigint, bigfloat,...)
> I think that all of those are easily defensible.

Geometric algebra things.
Here's a file from a GA library I just found:

I see "rotors" and "bivectors" being used with operator overloads in
addition to some of the other types above.  Also saw the keywords
"multivector" "versor" and "blade" appearing elsewhere.  Not sure if
those are types that have op overloads or not.

One thing I've heard about GA is that it doesn't lead to very
efficient code.  So it's perhaps better for working ideas out than for
actually implementing them.  But that might make it a very interesting
target for an operator overloading/merging/optimizing framework.   By
that I mean that with sufficiently capable analysis, it may be
possible to turn even GA operations into optimal code.  That would be
a pretty big coup for D I think.


More information about the Digitalmars-d mailing list