templating opEquals/opCmp (e.g. for DSL/expression templates)

Nicholas Wilson iamthewilsonator at hotmail.com
Wed Feb 13 02:00:32 UTC 2019


On Wednesday, 13 February 2019 at 01:24:45 UTC, Rubn wrote:
> Always hear that D is somehow better than C++ for operators but 
> it isn't in quite a few places already.
>
>     int a;
>     auto c = (a) <= 0; // ok
>     auto d = (a) => 0; // not ok

Oooh. That one's nasty! Technically unambiguous, but nasty!

> For some reason Walter thought in D if you overload the "+" 
> operator you couldn't make it not commutative?? Still never got 
> a reply to that, so I'll just assume he didn't know what 
> commutative was. Yes you can make "a + b != b + a" be true 
> quite easily.

With opBinary doing something completely different to 
opBinaryRight? Anyway that falls under the category of deliberate 
abuse, something we should not be considering, if people do that 
kind of thing then they should get what they deserve.

>
> Then you have things like "min" where you can do:
>
>     foo( a /min/ b );
>
> To get the "min" value between a and b. I guess you could use 
> this as an example of why not to allow. But at the same time, 
> we're already pretty much there. That includes "==" operator in 
> that. So the comparisons operators aren't even consistent.

Indeed.


More information about the Digitalmars-d mailing list