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
If you want to search also in values then may be better to use Boost Bimap in order not to be slow?
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<int,ValueType>
. 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<std::pair<int,ValueType>,bool>
{
XEquals(int _x)
: x(_x) {}
bool operator()(const std::pair<int,ValueType> &v) const
{ return p.second.x == x; }
int x;
};