.\" ident @(#)min.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH min 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2min\fP \ - Finds and returns the minimum of a pair of values. .SH SYNOPSIS .br #include .br template .br const T& min(const T&, const T&); .br .br template .br const T& min(const T& a, const T&, Compare); .SH DESCRIPTION The min algorithm determines and returns the minimum of a pair of values. In the second version of the algorithm, the optional argument \f2Compare\fP defines a comparison function that can be used in place of the default \f2operator<\fP. min returns the first argument when the two arguments are equal. .SH EXAMPLE .br // .br // max.cpp .br // .RE .RS 1 #include .br #include .RE .RS 0 using namespace std; .br .br int main(void) .RE .RS 1 { .RE .RS 2 double d1 = 10.0, d2 = 20.0; .RE .RS 1 .RE .RS 3 // Find minimum .RE .RS 2 double val1 = min(d1, d2); .RE .RS 3 // val1 = 10.0 .RE .RS 1 .RE .RS 3 // the greater comparator returns the greater of the .br // two values. .RE .RS 2 double val2 = min(d1, d2, greater()); .RE .RS 3 // val2 = 20.0; .RE .RS 1 .RE .RS 3 // Find maximum .RE .RS 2 double val3 = max(d1, d2); .RE .RS 3 // val3 = 20.0; .RE .RS 1 .RE .RS 3 // the less comparator returns the smaller of the .br // two values. .br // Note that, like every comparison in the STL, max is .br // defined in terms of the < operator, so using less here .br // is the same as using the max algorithm with a default .br // comparator. .RE .RS 2 double val4 = max(d1, d2, less()); .RE .RS 3 // val4 = 20 .RE .RS 0 .RE .RS 2 cout << val1 << " " << val2 << " " .RE .RS 8 << val3 << " " << val4 << endl; .RE .RS 1 .RE .RS 2 return 0; .RE .RS 1 } .br .RE .RS 0 Program Output .RE .RS 0 .br 10 20 20 20 .SH SEE ALSO max, max_element, min_element