Download

Mistakes in documentation

I’ve just found a few mistakes in Coding Standard page https://docs.unrealengine.com/en-us/Programming/Development/CodingStandard
I’m talking about this


    TMap<FString, int32> MyMap;
    // Old style
    for (auto It = MyMap.CreateIterator(); It; ++It)
    {
        UE_LOG(LogCategory, Log, TEXT("Key: %s, Value: %d"), It.Key(), *It.Value());
    }
    // New style
    for (TPair<FString, int32>& Kvp : MyMap)
    {
        UE_LOG(LogCategory, Log, TEXT("Key: %s, Value: %d"), Kvp.Key, *Kvp.Value);
    }

But it’s of course is not compilable, it should be


*Kvp.Key, Kvp.Value

And the second is - should we use


const TPair<FString, int32>& Kvp

as explained in “Const Correctness” section?

Thank you! We’re fixing the “*” placement. The “const” usage could be better, though it’s not needed to illustrate the concept we’re discussing in that section, and it’s only because our sample code happens not to do anything non-const. We could also use CreateConstIterator() in the “auto” portion to keep things similar.