Overloading relational operators separately; thoughts?

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 1 04:53:07 PDT 2016


On 10/1/16 7:33 AM, Andrei Alexandrescu wrote:
> On 10/1/16 3:13 AM, Martin Nowak wrote:
>> The fact that it's not possible to overload < but have to use the
>> ternary opCmp is even a performance problem. All std algorithms only use
>> less as a predicate, leading to lots of unnecessary cycles when e.g.
>> sorting UDTs.
>
> I've also been often annoyed by having to write
>
> return a < b ? -1 : a > b;
>
> in e.g. checkedint. Does inlining take care of this? -- Andrei

Apparently in dmd the generated code is less efficient: 
https://goo.gl/OWxbA0. In gdc it's the same: 
https://godbolt.org/g/NmUyXM. I couldn't test with ldc, 
http://ldc.acomirei.ru seems down. -- Andrei



More information about the Digitalmars-d mailing list