← Back to context

Comment by ryao

4 months ago

That does not show the comparator being inlined since everything was folded into a constant, although I suppose it was. Neat.

Edit: It sort of works for the bsearch() standard library function:

https://godbolt.org/z/3vEYrscof

However, it optimized the binary search into a linear search. I wanted to see it implement a binary search, so I tried with a bigger array:

https://godbolt.org/z/rjbev3xGM

Now it calls bsearch instead of inlining the comparator.

With optimization, it will really inline it with an unknown size array: https://godbolt.org/z/sK3nK34Y4

That's not the most general case, but it's better than I expected.