Suppose a container (in this case a plain array) storing elements like
struct Foo
{
char id[8];
// other members
};
Now I want to find a Foo
whose id begins with a particular string S
. Since the array is sorted by id, I want to use binary search, so I look for a function which perform binary search with the same interface as find_if. Is there such a function in STL, can it be constructed by using other elements in algorithm
, or do I need to implement it my self.
I believe you're looking for std::binary_search or std::lower_bound.