How to iterate through a TMap via range-based For loop

The example of a ranged-based for loop on the Epic documentation uses “Auto” in its example for TMap. This obfuscates the actual type that the iterator returns, making it hard to look up what functions are available to the returned object.

Here is how to do a ranged-based for loop in TMap properly:

TMap<int32, AActor*> exampleIntegerToActorMap;
for (const TPair<int32, AActor* >& pair : exampleIntegerToActorMap)
{
	pair.Key;
	pair.Value;
}
11 Likes

TMap<int32, AActor*> exampleIntegerToActorMap;
for (const TPair<int32, AActor*>& pair : exampleIntegerToActorMap)
{
pair.Key;
pair.Value;
}

11 Likes