mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
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:
commit
ef2ef926a5
@ -29,7 +29,6 @@
|
||||
#![feature(bool_to_option)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(cmp_min_max_by)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(const_panic)]
|
||||
#![feature(core_intrinsics)]
|
||||
|
@ -1059,8 +1059,6 @@ pub fn min<T: Ord>(v1: T, v2: T) -> T {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(cmp_min_max_by)]
|
||||
///
|
||||
/// use std::cmp;
|
||||
///
|
||||
/// 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]
|
||||
#[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 {
|
||||
match compare(&v1, &v2) {
|
||||
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
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(cmp_min_max_by)]
|
||||
///
|
||||
/// use std::cmp;
|
||||
///
|
||||
/// 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]
|
||||
#[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 {
|
||||
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
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(cmp_min_max_by)]
|
||||
///
|
||||
/// use std::cmp;
|
||||
///
|
||||
/// 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]
|
||||
#[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 {
|
||||
match compare(&v1, &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
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(cmp_min_max_by)]
|
||||
///
|
||||
/// use std::cmp;
|
||||
///
|
||||
/// 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]
|
||||
#[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 {
|
||||
max_by(v1, v2, |v1, v2| f(v1).cmp(&f(v2)))
|
||||
}
|
||||
|
@ -57,7 +57,6 @@
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(iter_is_partitioned)]
|
||||
#![feature(iter_order_by)]
|
||||
#![feature(cmp_min_max_by)]
|
||||
#![feature(iter_map_while)]
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_pin)]
|
||||
|
Loading…
Reference in New Issue
Block a user