#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
.
a
, b
- arguments to be compared
p
- comparison function which returns true
if the first parameter is less than the second
the lesser of the given arguments
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; }
constant