This may seem to be an academic question, but still I would be very interested in the answer:
I have a vector of strings s
in which I would like to find a given string findme
. This can be done using something like
find(s.begin(), s.end(), findme);
My question is: There must be a way doing the same using find_if
and the compare
method of the STL strings as predicate, but how? Something like
find_if(s.begin(), s.end(), bind2nd(mem_fun_ref(&string::compare), string("findme")) );
does not work, because the compare method has several overloads and the compiler does not know which one to choose.
As a second step: My motivation for using find_if instead of find is that I have a vector of objects derived from a class having a string property name
and I want to find an object with a given name. Is this possible (without writing an extra function to be used as predicate)?
EDIT: As some (most :) answers mentioned using Boost -- I would prefer not to have to include Boost for this. (As far as I know, most of the Boost libraries are "only" templates, so there should be a way without using Boost.)