Name
min_element function template — Finds the smallest value in a range
Synopsis
template<typename FwdIter> FwdIter min_element(FwdIter first, FwdIter last); template<typename FwdIter, typename Compare> FwdIter min_element(FwdIter first, FwdIter last, Compare comp);
The min_element
function
template returns an iterator that points to the smallest element in
the range [first
, last
). If there are multiple instances of
the smallest element, the iterator points to the first such
instance.
The first form compares values using the <
operator. The second form calls
comp(*iter1
, *iter2)
.
Technical Notes
The min_element
function
template returns first +
n, in which n is the smallest value in [0, last - first) such that for all m in [0,
last - first), *(first + m) < *(first + n) is false.
Complexity is linear: exactly max(last - first - 1, 0) comparisons are performed.
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.