Daily Unreal Column #67 - Algo::AnyOf
Let's talk about another great utility function from the Algo namespace, AnyOf.
Following the recent trend of covering different utility functions from the Algo::
namespace, today I would like to bring AnyOf
to your attention.
Searching through a container to see if any of it’s element is meeting our requirements for something to happen is bread and butter of making a game. Using this function we can do this within a single line of code.
TArray<AActor*> Actors;
bool bResult = Algo::AnyOf(Actors, [](const AActor* Actor)
{
return Actor->GetActorLocation().X > 1000.0f;
}
With the above code, the AnyOf
function will return true if any of the actor’s X component of their location is greater than 1000 units.