# std: Restore conventional \`compareFn\` behavior for \`binarySearch\` · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/812557bfde3c577b5f00cb556201c71ad5ed6fa4)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 812557bfde3c577b5f00cb556201c71ad5ed6fa4

Requested commit: 812557bfde3c577b5f00cb556201c71ad5ed6fa4

Commit: 812557bfde3c577b5f00cb556201c71ad5ed6fa4

Tree: 78dc955c7aa665ea95f32a3820903f63c025aed7

Author: Jay Petacat

Committer: Andrew Kelley

## Message

```
std: Restore conventional `compareFn` behavior for `binarySearch`

PR #20927 made some improvements to the `binarySearch` API, but one
change I found surprising was the relationship between the left-hand and
right-hand parameters of `compareFn` was inverted. This is different
from how comparison functions typically behave, both in other parts of
Zig (e.g. `std.math.order`) and in other languages (e.g. C's `bsearch`).
Unless a strong reason can be identified and documented for doing
otherwise, I think it'll be better to stick with convention.

While writing this patch and changing things back to the way they were,
the predicates of `lowerBound` and `upperBound` seemed to be the only
areas that benefited from the inversion. I don't think that benefit is
worth the cost, personally. Calling `Order.invert()` in the predicates
accomplishes the same goal.

```

## Parents

- [7caa3d9da71c38665340247a1c2bf9bedb8db925](https://git.cafe/gitcafe/zig/commit/7caa3d9da71c38665340247a1c2bf9bedb8db925?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/812557bfde3c577b5f00cb556201c71ad5ed6fa4?format=markdown)
