Are there examples of using Container Find with a predicate?

I already use Sort on my TArray which uses a predicate which is really nice. However, when I need to find an item inside my container I need iterate over it using a for loop, perform a test and then break if I find a match.

I notice there is a Find method and I was wondering whether if it is possible to find an item by member property value using a predicate?

Are there any examples of using this type of predicate?

1 Like

Hi Nathan,

There is a FindByPredicate function:

// Find first odd number
if (const int32* Val = MyArrayOfInts.FindByPredicate([](int32 n){ return n % 1; }))
{
    // Val points to odd number
}

Hope this helps.

Steve

2 Likes

Yes it does help. Thanks Steve. :slight_smile: