Rather than evaluate the condition over each item in the collection, I think I'd start by using std::minmax_element
to find the smallest and largest elements in the collection.
From there, it's a simple matter of testing whether result.first < minimum
and/or result.second > maximum
.
Dealing with the tolerance is basically a matter of repeating the test with the expanded range.
As to whether this is likely to be better than std::find_if
or std::all_of
, it'll depend on both the number of items you expect in the collection and the likelihood of finding a value out of range that would have allowed early exit. I think you'd need some knowledge of the data to give a meaningful prediction about it.