Translations of this page?:

min

#include <algorithm>
 
template< class T >
const T& min( const T& a, const T& b );
 
template< class T, class Compare >
const T& min( const T& a, const T& b, Compare comp );

Compares two elements and returns the lesser one. One version of the function uses operator< to compare the arguments, another uses the compare function p.

Parameters

a, b - arguments to be compared

p - comparison function which returns true if the first parameter is less than the second

Return value

the lesser of the given arguments

Equivalent function

First version:

template<class T>
const T& min(const T& a, const T& b)
{
    return (a < b) ? a : b;
}

Second version:

template<class T, class Compare>
const T& min(const T& a, const T& b, Compare comp)
{
    return (comp(a, b)) ? a : b;
}

Complexity

constant

See also

 
• • • SitemapRecent changesRSScc