On Thursday, 5 December 2013 at 18:26:48 UTC, Jonathan M Davis wrote:
To be fair, you can't solve the problem automatically. It's fundamentally wrong to compare signed and unsigned values, and doing either the conversion to unsigned or to signed could be wrong (or both could be wrong), depending on
the values.

*Actually*... that's not exactly true.

std.algorithm.max and std.algorithm.min actually do it perfectly well.

It is completely feaseable to imagine having an:
std.functional.less(T, U)(T t, U u){}

Which could work for *any* (compatible) type, including those with mixed signed-ness.

The only "issue" is that if the signs *are* mixed, the comparison is a *bit* more costly. It involved *two* comparisons, and a boolean condition:
https://github.com/D-Programming-Language/phobos/blob/ab34fb92addca61755474df04a0d0d6e0f1148a2/std/algorithm.d#L6698

Truth be told, "a < b" could work correctly 100% of the time, no question asked, if the *language* wanted to. The (2) problems would be:
1) Breaks backward compatibility with C and C++.
2) Higher (and hidden) comparison costs.

Try to convince Walter that these are worth it XD !

Reply via email to