]> git.lizzy.rs Git - rust.git/commitdiff
cmp: Implement all PartialOrd methods for Reverse
authorUlrik Sverdrup <bluss@users.noreply.github.com>
Thu, 30 Mar 2017 15:25:36 +0000 (17:25 +0200)
committerUlrik Sverdrup <bluss@users.noreply.github.com>
Thu, 30 Mar 2017 15:29:19 +0000 (17:29 +0200)
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.

src/libcore/cmp.rs

index dc2398b22acec67e6dbd98f1c94a9698a266c4ef..74ded948b18e74a8dad5126880f24bea19585372 100644 (file)
@@ -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")]