mardi 28 juillet 2015

How to find object in container by value, not key

I have a map with <int, int*>

I want to search the map for a specific value (not key) and retrieve the iterator that points to the correct int* (value of the map)

Can I use the std::find_if() ?

auto it = std::find_if(map.begin(), map.end(), compare);

where the compare should be something like:

bool compare(int* v1, int* v2)
{
 return (v1==v2);
}

What is the best way to acomplish this?

Aucun commentaire:

Enregistrer un commentaire