John Black <bl***@eed.com> wrote in message news:<40***************@eed.com>...
But the problem is I must use a function as search condition, actually the
reason is simple, this is how I implement isAvailable():
if (...this->pool has a pair which 'cover' the given pair... ) {
return true;
}
Here one pair 'cover' another means that this pair's first is less and
equals than the other's first and its second is large and equals to the
other's second.
Any suggestions?
Well .. it seems there may be two levels of iteration here ..
otherwise I don't understand why you need std::find_if. Your stated
implementation of isAvailable seems to be mimicking the operation of
std::find_if anyway.
So, if all you want to do is search a vector of pair<int,int> (inside
a Pool object) for the first instance satisfying your "cover"
conditions, then just write something like:
// Note that I have added std:: where you omitted it and also made
some
// necessary assumptions to answer your question. If my assumptions
are
// wrong, re-post with some more details and I will work from there
bool covers(const std::pair<int,int>& a, const std::pair<int,int>& b)
{
return a.first<=b.first && a.second>=b.second;
}
void func(Pool &pool, int base, int high) {
// I am assuming here that Pool has the appropriate typedef's and
forwarding
// functions for the following code to work
Pool::iterator itr = std::find_if(pool.begin(), pool.end(),
std::bind2nd(std::ptr_fun(covers),
std::make_pair(base,high)));
// rest of function using result
}
If there is another level of "finding" that needs to be done, you can
post some more details and I will try to help you more.
HTH, Dave Moore