C++ – What function in the std library is there to binary search a vector and find an element


I've got a node struct

struct Node{CString text, int id;};

in a sorted vector.

I'm wondering if there's a function in algorithm that will do a binary search of the vector and find an element.

Best Solution

std::binary_search() will tell you if a value exists in the container.

std::lower_bound()/std::upper_bound() will return an iterator to the first/last occurrence of a value.

Your objects need to implement operator< for these algorithms to work.