Add more comparison default methods to the `PartialOrd` trait.
This allows for some optimization.
This commit is contained in:
parent
becb77843e
commit
9fb67f8125
|
@ -83,6 +83,26 @@ macro_rules! ord_impl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn partial_lt(a: &$t<N>, b: &$t<N>) -> bool {
|
||||||
|
a.$comp0 < b.$comp0 $(&& a.$compN < b.$compN)*
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn partial_le(a: &$t<N>, b: &$t<N>) -> bool {
|
||||||
|
a.$comp0 <= b.$comp0 $(&& a.$compN <= b.$compN)*
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn partial_gt(a: &$t<N>, b: &$t<N>) -> bool {
|
||||||
|
a.$comp0 > b.$comp0 $(&& a.$compN > b.$compN)*
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn partial_ge(a: &$t<N>, b: &$t<N>) -> bool {
|
||||||
|
a.$comp0 >= b.$comp0 $(&& a.$compN >= b.$compN)*
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -80,6 +80,30 @@ pub trait PartialOrd {
|
||||||
/// Compare `a` and `b` using a partial ordering relation.
|
/// Compare `a` and `b` using a partial ordering relation.
|
||||||
fn partial_cmp(a: &Self, b: &Self) -> PartialOrdering;
|
fn partial_cmp(a: &Self, b: &Self) -> PartialOrdering;
|
||||||
|
|
||||||
|
/// Returns `true` iff `a` and `b` are comparable and `a <= b`.
|
||||||
|
#[inline]
|
||||||
|
fn partial_le(a: &Self, b: &Self) -> bool {
|
||||||
|
PartialOrd::partial_cmp(a, b).is_le()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` iff `a` and `b` are comparable and `a < b`.
|
||||||
|
#[inline]
|
||||||
|
fn partial_lt(a: &Self, b: &Self) -> bool {
|
||||||
|
PartialOrd::partial_cmp(a, b).is_lt()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` iff `a` and `b` are comparable and `a >= b`.
|
||||||
|
#[inline]
|
||||||
|
fn partial_ge(a: &Self, b: &Self) -> bool {
|
||||||
|
PartialOrd::partial_cmp(a, b).is_ge()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns `true` iff `a` and `b` are comparable and `a > b`.
|
||||||
|
#[inline]
|
||||||
|
fn partial_gt(a: &Self, b: &Self) -> bool {
|
||||||
|
PartialOrd::partial_cmp(a, b).is_gt()
|
||||||
|
}
|
||||||
|
|
||||||
/// Return the minimum of `a` and `b` if they are comparable.
|
/// Return the minimum of `a` and `b` if they are comparable.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn partial_min<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> {
|
fn partial_min<'a>(a: &'a Self, b: &'a Self) -> Option<&'a Self> {
|
||||||
|
|
Loading…
Reference in New Issue