Partilhar via


minmax_element

Performs the work performed by min_element and max_element in one call.

template<class ForwardIterator>
    pair< ForwardIterator, ForwardIterator >
        minmax_element(
            ForwardIterator _First, 
            ForwardIterator _Last
 );
template<class ForwardIterator, class BinaryPredicate>
    pair< ForwardIterator, ForwardIterator >
        minmax_element(
            ForwardIterator _First, 
            ForwardIterator _Last, 
            BinaryPredicate _Comp
);

Parameters

  • _First
    A forward iterator that indicates the beginning of a range.

  • _Last
    A forward iterator that indicates the end of a range.

  • _Comp
    An optional test used to order elements.

Return Value

Returns

pair<ForwardIterator, ForwardIterator>

(min_element(_First, _Last), max_element(_First, _Last)).

Remarks

The first template function returns

pair<ForwardIterator,ForwardIterator>

(min_element(_First, _Last),max_element(_First, _Last)).

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

If the sequence is non-empty, the function performs at most 3 * (_Last - _First - 1) / 2 comparisons.

Requirements

Header: <algorithm>

Namespace: std

See Also

Reference

minmax_element

min

min_element

max

max_element

<algorithm>

Standard Template Library

Other Resources

<algorithm> Members