Suppose I have an std::vector<int>:
std::vector<int> v;
[v is initialized]
and I want to get the maximum element of v. There is an algorithm for doing that:
int max_value = *std::max_element(v.begin(), v.end());
So far, so good.
Now, suppose that v contains 10,000,000 elements, and its 10th element is equal to std::numeric_limits<int>::max(). Is std::max_element() going to (unnecessarily) examine the 9,999,990 last elements of v, or is it going to recognize that there cannot be elements larger than std::numeric_limits<int>::max(), and thus stop after the 10th element?