Shortcomings of D-Style Fused Operator Overloading

Dennis dkorpel at gmail.com
Fri Jul 7 11:02:16 UTC 2023


On Friday, 7 July 2023 at 09:18:38 UTC, Ahmet Sait wrote:
> So what do you guys think? Would you say distinct operators are 
> better?

The thing is, D's operator overloading was designed to support 
library numeric types, such as half float, fixed point, complex 
numbers, vector3 etc. It's intentionally limited in order to 
prevent Domain Specific Languages embedded in D code directly. 
Templates / string mixins can still be used for that.

Now there are other mathematical objects that could *almost* be 
modeled as a D type with operator overloading, but then it only 
gets you 90% there before you hit a limitation like  `opCmp` for 
your interval. I have a similar case where my symbolic number 
type could use an `opCmp` returning another `typeof(this)` 
instead of an `int` or `float`, but alas.

I don't think a proposal to make operator overloading a lot more 
powerful has much chance, but only making `opCmp` a bit more 
powerful might if you can demonstrate valid use cases for it.


More information about the Digitalmars-d mailing list