
Category: algorithms  Component type: function 
template <class ForwardIterator> ForwardIterator max_element(ForwardIterator first, ForwardIterator last); template <class ForwardIterator, class BinaryPredicate> ForwardIterator max_element(ForwardIterator first, ForwardIterator last, BinaryPredicate comp);
The two versions of max_element differ in how they define whether one element is less than another. The first version compares objects using operator<, and the second compares objects using a function object comp.
The first version of max_element returns the first iterator i in [first, last) such that, for every iterator j in [first, last), *i < *j is false. The second version returns the first iterator i in [first, last) such that, for every iterator j in [first, last), comp(*i, *j) is false.
int main() { list<int> L; generate_n(front_inserter(L), 1000, rand); list<int>::const_iterator it = max_element(L.begin(), L.end()); cout << "The largest element is " << *it << endl; }
Contact Us  Site Map  Trademarks  Privacy  Using this site means you accept its Terms of Use 
Copyright © 2009  2017 Silicon Graphics International. All rights reserved. 