+ /// Returns the element that gives the maximum value with respect to the
+ /// specified comparison function.
+ ///
+ /// Returns the rightmost element if the comparison determines two elements
+ /// to be equally maximum.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(iter_max_by)]
+ /// let a = [-3_i32, 0, 1, 5, -10];
+ /// assert_eq!(*a.iter().max_by(|x, y| x.cmp(y)).unwrap(), 5);
+ /// ```
+ #[inline]
+ #[unstable(feature = "iter_max_by", issue="36105")]
+ fn max_by<F>(self, mut compare: F) -> Option<Self::Item>
+ where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,
+ {
+ select_fold1(self,
+ |_| (),
+ // switch to y even if it is only equal, to preserve
+ // stability.
+ |_, x, _, y| Ordering::Greater != compare(x, y))
+ .map(|(_, x)| x)
+ }
+