Auto merge of #81047 - glittershark:stabilize-cmp-min-max-by, r=kodraus

Stabilize cmp_min_max_by

I would like to propose cmp::{min_by, min_by_key, max_by, max_by_key}
for stabilization.

These are relatively simple and seemingly uncontroversial functions and
have been unchanged in unstable for a while now.

Closes: #64460
This commit is contained in:
bors 2021-04-07 18:02:21 +00:00
commit ef2ef926a5
3 changed files with 4 additions and 14 deletions

View File

@ -29,7 +29,6 @@
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(box_patterns)] #![feature(box_patterns)]
#![feature(box_syntax)] #![feature(box_syntax)]
#![feature(cmp_min_max_by)]
#![feature(const_fn)] #![feature(const_fn)]
#![feature(const_panic)] #![feature(const_panic)]
#![feature(core_intrinsics)] #![feature(core_intrinsics)]

View File

@ -1059,8 +1059,6 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(cmp_min_max_by)]
///
/// use std::cmp; /// use std::cmp;
/// ///
/// assert_eq!(cmp::min_by(-2, 1, |x: &i32, y: &i32| x.abs().cmp(&y.abs())), 1); /// assert_eq!(cmp::min_by(-2, 1, |x: &i32, y: &i32| x.abs().cmp(&y.abs())), 1);
@ -1068,7 +1066,7 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
/// ``` /// ```
#[inline] #[inline]
#[must_use] #[must_use]
#[unstable(feature = "cmp_min_max_by", issue = "64460")] #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T { pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
match compare(&v1, &v2) { match compare(&v1, &v2) {
Ordering::Less | Ordering::Equal => v1, Ordering::Less | Ordering::Equal => v1,
@ -1083,8 +1081,6 @@ pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(cmp_min_max_by)]
///
/// use std::cmp; /// use std::cmp;
/// ///
/// assert_eq!(cmp::min_by_key(-2, 1, |x: &i32| x.abs()), 1); /// assert_eq!(cmp::min_by_key(-2, 1, |x: &i32| x.abs()), 1);
@ -1092,7 +1088,7 @@ pub fn min_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
/// ``` /// ```
#[inline] #[inline]
#[must_use] #[must_use]
#[unstable(feature = "cmp_min_max_by", issue = "64460")] #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T { pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
min_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2))) min_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
} }
@ -1125,8 +1121,6 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(cmp_min_max_by)]
///
/// use std::cmp; /// use std::cmp;
/// ///
/// assert_eq!(cmp::max_by(-2, 1, |x: &i32, y: &i32| x.abs().cmp(&y.abs())), -2); /// assert_eq!(cmp::max_by(-2, 1, |x: &i32, y: &i32| x.abs().cmp(&y.abs())), -2);
@ -1134,7 +1128,7 @@ pub fn max<T: Ord>(v1: T, v2: T) -> T {
/// ``` /// ```
#[inline] #[inline]
#[must_use] #[must_use]
#[unstable(feature = "cmp_min_max_by", issue = "64460")] #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T { pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
match compare(&v1, &v2) { match compare(&v1, &v2) {
Ordering::Less | Ordering::Equal => v2, Ordering::Less | Ordering::Equal => v2,
@ -1149,8 +1143,6 @@ pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// #![feature(cmp_min_max_by)]
///
/// use std::cmp; /// use std::cmp;
/// ///
/// assert_eq!(cmp::max_by_key(-2, 1, |x: &i32| x.abs()), -2); /// assert_eq!(cmp::max_by_key(-2, 1, |x: &i32| x.abs()), -2);
@ -1158,7 +1150,7 @@ pub fn max_by<T, F: FnOnce(&T, &T) -> Ordering>(v1: T, v2: T, compare: F) -> T {
/// ``` /// ```
#[inline] #[inline]
#[must_use] #[must_use]
#[unstable(feature = "cmp_min_max_by", issue = "64460")] #[stable(feature = "cmp_min_max_by", since = "1.53.0")]
pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T { pub fn max_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
max_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2))) max_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
} }

View File

@ -57,7 +57,6 @@
#![feature(iter_intersperse)] #![feature(iter_intersperse)]
#![feature(iter_is_partitioned)] #![feature(iter_is_partitioned)]
#![feature(iter_order_by)] #![feature(iter_order_by)]
#![feature(cmp_min_max_by)]
#![feature(iter_map_while)] #![feature(iter_map_while)]
#![feature(const_mut_refs)] #![feature(const_mut_refs)]
#![feature(const_pin)] #![feature(const_pin)]