#![stable(feature = "rust1", since = "1.0.0")]
-use crate::const_closure::ConstFnMutClosure;
use crate::marker::Destruct;
use self::Ordering::*;
Self: Sized,
Self: ~const Destruct,
{
- #[cfg(not(bootstrap))]
- {
- max_by(self, other, Ord::cmp)
- }
-
- #[cfg(bootstrap)]
- match self.cmp(&other) {
- Ordering::Less | Ordering::Equal => other,
- Ordering::Greater => self,
- }
+ max_by(self, other, Ord::cmp)
}
/// Compares and returns the minimum of two values.
Self: Sized,
Self: ~const Destruct,
{
- #[cfg(not(bootstrap))]
- {
- min_by(self, other, Ord::cmp)
- }
-
- #[cfg(bootstrap)]
- match self.cmp(&other) {
- Ordering::Less | Ordering::Equal => self,
- Ordering::Greater => other,
- }
+ min_by(self, other, Ord::cmp)
}
/// Restrict a value to a certain interval.
F: ~const Destruct,
K: ~const Destruct,
{
- cfg_if! {
- if #[cfg(bootstrap)] {
- const fn imp<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(
- f: &mut F,
- (v1, v2): (&T, &T),
- ) -> Ordering
- where
- T: ~const Destruct,
- K: ~const Destruct,
- {
- f(v1).cmp(&f(v2))
- }
- min_by(v1, v2, ConstFnMutClosure::new(&mut f, imp))
- } else {
- min_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
- }
- }
+ min_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
}
/// Compares and returns the maximum of two values.
F: ~const Destruct,
K: ~const Destruct,
{
- const fn imp<T, F: ~const FnMut(&T) -> K, K: ~const Ord>(
- f: &mut F,
- (v1, v2): (&T, &T),
- ) -> Ordering
- where
- T: ~const Destruct,
- K: ~const Destruct,
- {
- f(v1).cmp(&f(v2))
- }
- max_by(v1, v2, ConstFnMutClosure::new(&mut f, imp))
+ max_by(v1, v2, const |v1, v2| f(v1).cmp(&f(v2)))
}
// Implementation of PartialEq, Eq, PartialOrd and Ord for primitive types