Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Miscellaneous
STL Algorithms
algorithm:
adjacent_find
binary_search
copy
copy_backward
count
count_if
equal
equal_range
fill
fill_n
find
find_end
find_first_of
find_if
for_each
generate
generate_n
includes
inplace_merge
iter_swap
lexicographical_compare
lower_bound
make_heap
max
max_element
merge
min
min_element
mismatch
next_permutation
nth_element
partial_sort
partial_sort_copy
partition
pop_heap
prev_permutation
push_heap
random_shuffle
remove
remove_copy
remove_copy_if
remove_if
replace
replace_copy
replace_copy_if
replace_if
reverse
reverse_copy
rotate
rotate_copy
search
search_n
set_difference
set_intersection
set_symmetric_difference
set_union
sort
sort_heap
stable_partition
stable_sort
swap
swap_ranges
transform
unique
unique_copy
upper_bound


min

function template
<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 );

Return the lesser of two arguments

Returns the lesser of a and b.

The comparison uses operator< for the first version, and comp for the second.

The behavior of this function template is equivalent to:
1
2
3
template <class T> const T& min ( const T& a, const T& b ) {
  return (a<b)?a:b;     // or: return comp(a,b)?a:b; for the comp version
}


Parameters

a, b
Items to compare.
T is any type supporting copy constructions and comparisons with operator<.
comp
Comparison function object that, taking two values of the same type, returns true if the first argument is to be considered less than the second, and false otherwise.

Return value

The lesser of its two arguments

Example

1
2
3
4
5
6
7
8
9
10
11
12
// min example
#include <iostream>
#include <algorithm>
using namespace std;
int main () {
  cout << "min(1,2)==" << min(1,2) << endl;
  cout << "min(2,1)==" << min(2,1) << endl;
  cout << "min('a','z')==" << min('a','z') << endl;
  cout << "min(3.14,2.72)==" << min(3.14,2.72) << endl;
  return 0;
}


Output:
min(1,2)==1
min(2,1)==1
min('a','z')==a
min(3.14,2.72)==2.72

See also