Sometimes the compiler does a lousy job with the error messages. Your problem is the find
algorithm.
unordered_map
& map
have their own find, which take the key as argument and returns an iterator. The algorithm is looking for the key:
auto it = hm.find(key);
if (it != hm.end())
{
// ...
}
The global find algorithm takes a search interval and a value as input. But it works with any container that meets some iterators constrains. In the case of a map the value is not the key, as in the unordered_map::find
but the (key, value) pair. The algorithm is looking for the (key, value) pair. You can declare your target value and use it like this:
unordered_map<int, int>::value_type target{ key, value };
auto it = find(hm.begin(), hm.end(), target);
if (it != hm.end())
{
// ...
}