Is -1 > 7 ?
monarch_dodra
monarchdodra at gmail.com
Fri Aug 9 10:35:14 PDT 2013
On Friday, 9 August 2013 at 15:28:10 UTC, Manfred Nowak wrote:
> michaelc37 wrote:
>> WTF -> -1 is greater than 7 ????
>
> From the docs:
>
> It is an error to have one operand be signed and the other
> unsigned for a
> <, <=, > or >= expression.
>
> -manfred
Interesting. I didn't know it was documented as being an outright
error, I thought it was just "surprising"...
I don't think Walter will ever accept to make it illegal though,
breaks too much code. If this was a change he was OK with, I
think we would have had it since day one, or at least, years ago.
Related: std.algorithm.max *is* sign aware, and you can use code
such as:
if (a == max(a, b))
I have an pull request which creates the premise of functional
"less"/"greater" operators, which are also sign aware:
https://github.com/D-Programming-Language/phobos/pull/1365/files
*If* it goes through, and *if* we make them public in
std.functional, then it allows code such as:
int a = -1;
size_t b = 7;
assert(a.less(b)); //Passes
More information about the Digitalmars-d-learn
mailing list