given a container like std::vector<T>
, where T
is a generic type for numerical quantities ( like int
, float
, etc ... ), I would like to have a predicate that takes as arguments :
I would like to have as an output:
true
)In the C++ standard library looks like there is not even the concept of range
and this is strange to me, simply because there are a lot of interesting algorithms and types, but nothing that could possibly serve my purposes in this case.
Before continuing on my own path, I ask, there is something like this in terms of types and algorithms in the C++ library ?
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.