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

The MPL Reference Manual: min_element
Front Page / Algorithms / Querying Algorithms / min_element

min_element

Synopsis

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

Description

Returns an iterator to the smallest element in Sequence.

Parameters

Parameter Requirement Description
Sequence Forward Sequence A sequence to be searched.
Pred Binary Lambda Expression A comparison criteria.

Expression semantics

For any Forward Sequence s and binary Lambda Expression pred:

typedef min_element::type i;
Return type:

Forward Iterator.

Semantics:

i is the first iterator in [begin::type, end::type) such that for every iterator j in [begin::type, end::type),

apply< pred, deref::type, deref::type >::type::value == false

Complexity

Linear. Zero comparisons if s is empty, otherwise exactly size::value - 1 comparisons.

Example

typedef vector types;
typedef min_element<
      transform_view< types,sizeof_<_1> >
    >::type iter;

BOOST_MPL_ASSERT(( is_same< deref::type, bool> ));