function template
<algorithm>
std::min default (1)template <class T> const T& min (const T& a, const T& b);custom (2)
template <class T, class Compare> const T& min (const T& a, const T& b, Compare comp);default (1)
template <class T> const T& min (const T& a, const T& b);custom (2)
template <class T, class Compare> const T& min (const T& a, const T& b, Compare comp);initializer list (3)
template <class T> T min (initializer_list<T> il);template <class T, class Compare> T min (initializer_list<T> il, Compare comp);default (1)
template <class T> constexpr const T& min (const T& a, const T& b);custom (2)
template <class T, class Compare> constexpr const T& min (const T& a, const T& b, Compare comp);initializer list (3)
template <class T> constexpr T min (initializer_list<T> il);template <class T, class Compare> constexpr T min (initializer_list<T> il, Compare comp);
Return the smallest
Returns the smallest of a and b. If both are equivalent, a is returned.The versions for initializer lists (3) return the smallest of all the elements in the list. Returning the first of them if these are more than one.
The function uses operator<
(or comp, if provided) to compare the values.
The behavior of this function template (C++98) is equivalent to:
1
2
3
template <class T> const T& min (const T& a, const T& b) {
return !(b<a)?a:b; // or: return !comp(b,a)?a:b; for version (2)
}
bool
. The value returned indicates whether the element passed as first argument is considered less than the second.
operator<
.
1
2
3
4
5
6
7
8
9
10
11
// min example
#include <iostream> // std::cout
#include <algorithm> // std::min
int main () {
std::cout << "min(1,2)==" << std::min(1,2) << '\n';
std::cout << "min(2,1)==" << std::min(2,1) << '\n';
std::cout << "min('a','z')==" << std::min('a','z') << '\n';
std::cout << "min(3.14,2.72)==" << std::min(3.14,2.72) << '\n';
return 0;
}
min(1,2)==1 min(2,1)==1 min('a','z')==a min(3.14,2.72)==2.72
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4