The cause of this is that template argument deduction for functions does not work when the arguments are in different positions in the parameter list for the two function calls. In the first example, the key type is std::string and the value type is int, so the template argument deduction can correctly determine that T is std::string and U is int. In the second example, the key type is int and the value type is std::string, so the deduction fails because the types are in a different order.

To fix this, you can explicitly specify the template arguments for the function call:

```c++
int key2 = getkey<int, std::string>(map2, "apple");
```

Alternatively, you can rearrange the order of the template parameters in the function definition to match the order of the types in the map:

```c++
template<typename T, typename U>
T getkey(const std::map<T, U>& m, const U& value) {
// ...
}
```

With this definition, both calls to the function will work without explicit template argument specification.
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence