For starters, the std::bind1st
and std::bind2nd
functions are deprecated. You should consider using std::bind
instead, which is much more generic and easier to use.
If you do want to use bind2nd
, then the function you pass in must be an adaptable function, a function object type that exports some extra type information. To convert a raw function pointer to an adaptable function, use the amusingly-named ptr_fun
function:
remove_if(coulours2.begin(), coulours2.end(),
bind2nd(ptr_fun(IsEqual), "purple"));
However, there's no need to define your own function here at all. Just use std::equal_to
:
remove_if(coulours2.begin(), coulours2.end(),
bind2nd(equal_to<string>(), "purple"));
As was mentioned in the comments, you're also using the erase/remove_if
pattern incorrect. Try this instead:
coulours2.erase(remove_if(coulours2.begin(), coulours2.end(),
bind2nd(equal_to<string>(), "purple")),
coulours2.end());
The "better" way to do this using std::bind
looks like this:
using namespace std::placeholders;
coulours2.erase(remove_if(coulours2.begin(), coulours2.end(),
bind(equal_to<string>(), _1, "purple")),
coulours2.end());
Or just use a lambda:
coulours2.erase(remove_if(colours2.being(), colours2.end(),
[](const string& elem) { return elem == "purple"; },
coulours2.end());