[Static if] Replace overload constraints with static if (comparison.d)#5147
Conversation
c32691f to
31da914
Compare
std/algorithm/comparison.d
Outdated
| */ | ||
| int cmp(alias pred = "a < b", R1, R2)(R1 r1, R2 r2) | ||
| if (isInputRange!R1 && isInputRange!R2 && !(isSomeString!R1 && isSomeString!R2)) | ||
| if (isInputRange!R1 && isInputRange!R2 || isSomeString!R1 && isSomeString!R2) |
There was a problem hiding this comment.
if (isInputRange!R1 && isInputRange!R2 && isSomeChar!(ElementType!R1) && isSomeChar!(ElementType!R2))
There was a problem hiding this comment.
Yeah, you have to be very careful with isSomeString in template constraints for range-based functions, because enums pass isSomeString but are not ranges.
std/algorithm/comparison.d
Outdated
| if (isInputRange!R1 && isInputRange!R2 || isSomeString!R1 && isSomeString!R2) | ||
| { | ||
| for (;; r1.popFront(), r2.popFront()) | ||
| static if (isInputRange!R1 && isInputRange!R2) |
There was a problem hiding this comment.
this will be true for all inputs, the is some string overload needs to come first
edit: as CircleCi and the auto-tester showed, it really would be a breaking change... |
|
My point was that the The auto tester errors look like the non-string inputs weren't being sent to the input range code path but instead being sent to the string code path. |
efea298 to
2f7a492
Compare
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
2f7a492 to
8097b12
Compare
Finally came around rebasing this one :) |
8097b12 to
171e81d
Compare
... and another rebase. This PR just combines the overloads of |
JackStouffer
left a comment
There was a problem hiding this comment.
Looks good. Go ahead and merge when the CI failures are fixed
| for (;; r1.popFront(), r2.popFront()) | ||
| { | ||
| if (r1.empty) return -cast(int)!r2.empty; | ||
| if (r2.empty) return !r1.empty; |
There was a problem hiding this comment.
I just noticed this is inefficient because at this point it is known that r1 is not empty. Normally you'd need to make a separate PR for that, but let's not let protocol getting in the way of good work. And how about you eliminate the cast - it's a nice conversion:
if (r1.empty) return -int(r2.empty);
if (r2.empty) return 1;This will fold two calls to r2.empty into one and perhaps generates better code:
immutable e1 = r1.empty, e2 = r2.empty;
if (e1) return -int(e2);
if (e2) return 1;
Split up of #5145