Overloading relational operators separately; thoughts?

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 27 21:02:59 PDT 2016


On 9/27/2016 6:18 PM, Minty Fresh wrote:
> So, I'm just interested in other people's thoughts are on the subject, and
> whether there are any plans to allow overloading these operators separately.

The limitations are deliberate based on the idea that comparison operators need 
to be consistent and predictable, and should have a close relationship to the 
mathematical meaning of the operators. Overloading <= to mean something other 
than "less than or equal" is considered poor style in D, and the same goes for 
the other arithmetic operators.

The use of them to create DSLs (a technique called "expression templates" in 
C++) is discouraged in D, for several reasons. The recommended way to create 
DSLs in D is to parse strings using CTFE. An excellent example of that is the 
std.regex package.

There are no plans to change this.


More information about the Digitalmars-d mailing list