max_element

template<class FwdIt>
    FwdIt max_element(FwdIt first, FwdIt last);
template<class FwdIt, class Pred>
    FwdIt max_element(FwdIt first, FwdIt last, Pred pr);

The first template function determines the lowest value of N in the range [0, last - first) such that, for each M in the range [0, last - first), the predicate *(first + N) < *(first + M) is false. It then returns first + N. Thus, the function determines the lowest position that contains the largest value in the sequence.

The function evaluates the ordering predicate X < Y exactly max((last - first) - 1, 0) times.

The second template function behaves the same, except that it replaces operator<(X, Y) with pr(X, Y).

Sample programs: max_element and max_element (predicate version).