[Issue 17418] opCmp return value unclear
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon May 22 10:47:34 PDT 2017
https://issues.dlang.org/show_bug.cgi?id=17418
Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |issues.dlang at jmdavisProg.co
| |m
--- Comment #1 from Jonathan M Davis <issues.dlang at jmdavisProg.com> ---
I would point out that the return values don't need to be spcecific numbers.
They only need to be < 0, == 0, or > 0. And requiring them to be -1, 0, and +1
would be less efficient in a number of cases. Now, looking over that page, I
agree that it's not as clear as it should be, and the problem seems to be that
it's focused on how the compiler is going to take the return value and use that
to generate the correct code for the comparison rather than what the programmer
needs to do with opCmp to make it work correctly. But from the perspective of
the person writing opCmp, opCmp should return a value < 0 if lhs < rhs, 0 if
lhs == rhs, and a value > 0 if lhs > rhs.
--
More information about the Digitalmars-d-bugs
mailing list