Skip to content

Commit

Permalink
cmp: Implement all PartialOrd methods for Reverse
Browse files Browse the repository at this point in the history
When making a forwarding wrapper we must in general forward all methods,
so that we use the type's own `lt` for example instead of the default.

Example important case: f32's partial_cmp does several operations but
its lt is a primitive.
  • Loading branch information
bluss committed Mar 30, 2017
1 parent fe15119 commit 6fda0fe
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/libcore/cmp.rs
Expand Up @@ -347,6 +347,15 @@ impl<T: PartialOrd> PartialOrd for Reverse<T> {
fn partial_cmp(&self, other: &Reverse<T>) -> Option<Ordering> {
other.0.partial_cmp(&self.0)
}

#[inline]
fn lt(&self, other: &Self) -> bool { other.0 < self.0 }
#[inline]
fn le(&self, other: &Self) -> bool { other.0 <= self.0 }
#[inline]
fn ge(&self, other: &Self) -> bool { other.0 >= self.0 }
#[inline]
fn gt(&self, other: &Self) -> bool { other.0 > self.0 }
}

#[unstable(feature = "reverse_cmp_key", issue = "40893")]
Expand Down

0 comments on commit 6fda0fe

Please sign in to comment.