I\'d like to use std::find_if
to search for the first element in my map that has a certain value in a specific element of its value structure. I\'m a little confus
This doesn't have anything to do with std::bind1st
or std::bind2nd
. First of all, you have to keep in mind that the elements of a map are key-value pairs, in your case std::pair
. Then you just need a predicate that compares the x member of the second member of yuch a pair against a specific value:
struct XEquals : std::unary_function,bool>
{
XEquals(int _x)
: x(_x) {}
bool operator()(const std::pair &v) const
{ return p.second.x == x; }
int x;
};