binary_search()
Assumes that the container is sorted by the less-than operator. If the container is sorted by some other ordering relationship, the binary operator must be passed in. The algorithm returns true or false.
#include <algorithm> found_it = binary_search( ilist.begin(), ilist.end(), value ); found_it = binary_search( vec.begin(), vec.end(), value, greater<int>() );
Get Essential C++ now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.