I stumbled on a compilation error when trying to make and use a custom KeyFuncs struct for a TMap, in the case the type of the key of the map and the “InKeyType” are different and not implicitly convertible to each other (see below snippet for clearer explanation)
template <typename MapValueType>
struct TMyStructMapKeyFuncs : BaseKeyFuncs<TPair<FMyStruct, MapValueType>, FString, false>
// This type ^^^ ^^^ and this type are different
{
//...
}
The compilation error happens when calling the TMap::Contains method, but I believe other functions like RemoveAndCopyValue and Find (and maybe others) suffer from the same problem. When we look at the TMap::Contains implementation, the Key parameter is a KeyConstPointerType (in our case, a const FMyStruct&), and it forwards it directly to its internal Pairs.Contains (which is essentially a TSet<TPair<MapKeyType, MapValueType>, MapKeyFuncs>). Problem is that TSet::Contains expects a KeyInitType, extracted from the KeyFuncs struct, which is a FString in our case. There’s no possible conversion which triggers the compilation error.
I think that TMap::Contains should look like something like this instead
Just for reference, as a workaround it works to write the TMap KeyFuncs like this instead. Is it the expected usage and the documentation is out-of-date, or the initial plan was to handle the type conversion in the TMap implementation?