Please read the new rule regarding the restriction on the use of AI tools. ×

1 line binary search in c++20

Revision en1, by Xylenox, 2024-10-05 15:12:42
auto res = *ranges::partition_point(views::iota(lo, hi), check);

this returns the first $$$x$$$ in the range $$$[lo, hi)$$$ such that check(x) is not true, or $$$hi$$$ if it doesn't exist. Be careful to make sure the $$$lo$$$ and $$$hi$$$ are both integers of the same type, otherwise there is weird behavior.

example usage: 284450329

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English Xylenox 2024-10-05 15:12:42 377 Initial revision (published)