I am trying to lean boost::bind, boost::lambda libraries and how they can be used with STL algorithms. Suppose I have vector of int-string pairs which is sorted by int key. Then a place to insert a new pair while keeping the vector sorted can be found as follows:
std::vector<std::pair<int, string> > entries;
...
int k = ...;
// Let's ignore std::lower_bound return value for now
std::lower_bound (entries.begin(), entries.end(), k,
boost::bind (&std::pair<int, string>::first, _1) < k)
Now I would like to replace operator<
with a function object (of type std::less<int>
in this example):
std::less<int> comparator;
How do I change the code above so it works? I cannot just do
std::lower_bound (entries.begin(), entries.end(), k,
comparator (boost::bind (&std::pair<int, string>::first, _1), k))
because std::less<int>::operator()
does not accept whatever is the return type of boost::bind
. What am I missing here? TIA