This is a somewhat more efficient binary_search, but it requires
that all key in the array are unique. It's more efficient because
it doesn't need two predicate compares to test for equality since
it uses a predicate which returns a stong_ordering-object.
Another advantage is, that the supplied key can have a differnt type
than the elements in the array; so you can f.e. check for an member
of an element.
Assuming than a three way comparison is often a bit more expensive,
it might even be less efficient for some collections.
Assuming than a three way comparison is often a bit more expensive, it
might even be less efficient for some collections.
And not only does it require a slower three-way comparison, ...
..., it also uses two conditionals instead of the one that std::binary_search/std::lower_bound uses.
|Location:||Huddersfield, West Yorkshire, UK|
|Nodes:||8 (0 / 8)|