# max_element

### Synopsis

    template<
          typename Sequence
        , typename Pred = less<_1,_2>
        >
    struct max_element
    {
        typedef unspecified type;
    };

### Description

Finds the largest element in the `Sequence`.

### Definition

    #include "boost/mpl/max_element.hpp"

### Parameters

Parameter | Requirement | Description
--- | --- | ---
`Sequence` | A model of Forward Sequence | A sequence to be searched.
`Pred` | A model of binary Predicate [Lambda Expression] | A comparison criteria.

### Expression semantics

Expression | Expression type | Precondition | Semantics | Postcondition
--- | --- | --- | --- | ---
`typedef max_element< Sequence,Pred >::type i;` | A model of Forward Iterator |  | `i` is the first iterator in `[begin<Sequence>::type, end<Sequence>::type)` such that for every iterator `j` in `[begin<Sequence>::type, end<Sequence>::type)`, `apply< lambda<Pred>::type, i::type, j::type >::type::value == false`. |

### Complexity

Linear. Zero comparisons if `Sequence` is empty, otherwise exactly `size<Sequence>::value - 1` comparisons.

### Example

    typedef vector<int,char[50],long,double> types;
    typedef max_element<
          transform_view< types,sizeof_<_1> >
        >::type iter;

    BOOST_STATIC_ASSERT((distance< begin<types>::type,iter >::type::value == 1));
    BOOST_STATIC_ASSERT(sizeof(deref<iter>::type) == 50);

### See also

Algorithms, `min_element`, `upper_bound`, `lower_bound`

Table of Contents
Last edited March 10, 2003 6:01 am