Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.

[Home]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  
SequenceA model of Forward SequenceA sequence to be searched.
PredA 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 Iteratori 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