We have some problems using find_if to find a vector of pairs for a record in which the first element of the pair corresponds to a specific value. To do this, we defined a trivial functor whose operator () takes a pair as input and compares the first record with the string.
Unfortunately, when we really add a find_if call using an instance of our functor built using a temporary string value, the compiler generates a lot of error messages. Oddly enough (for me, anyway), if we replace the temporary line that we created on the stack, everything works.
Here the code (including both versions) looks like this:
typedef std::pair<std::string, std::string> MyPair;
typedef std::vector<MyPair> MyVector;
struct MyFunctor: std::unary_function <const MyPair&, bool>
{
explicit MyFunctor(const std::string& val)
: m_val(val) {}
bool operator() (const MyPair& p)
{
return p.first == m_val;
}
const std::string m_val;
};
bool f(const char* s)
{
MyFunctor f(std::string(s));
MyVector vec;
MyVector::const_iterator i = std::find_if(vec.begin(), vec.end(), f);
return i != vec.end();
}
And here is what the most interesting error message looks like:
/usr/include/++/4.2.1/bits/stl_algo.h: 260: : 'std:: pair, std:: allocator > , std:: basic_string, std:: allocator → std::string
, , . , - , , .