Search code examples
predicatec++

What is wrong with this usage of std::find_if?


I get the following error when compiling the std::find_if function:

error C2451: conditional expression of type 'overloaded-function' is illegal

The code looks like this:

typedef std::vector<boost::shared_ptr<node> >::iterator nodes_iterator;

nodes_iterator node_iter = std::find_if(_request->begin(), _request->end(), boost::bind(&RequestValues::is_parameter, this));

bool RequestValues::is_parameter(nodes_iterator iter)
{
   return ((*iter)->name.compare("parameter") == 0);
}

It seems to have something to do with the predicate function passed to the std::find_if, however I cannot figure out what is wrong, can anybody help?

node is a struct containing some values.


Solution

  • You should use _1, not this when binding, and take a value_type as an argument of your function.

    If this is a class or struct member function, then bind(func, this, _1) maybe? But if it is a class member function it should probably be static because it needn't state.