std: implement Total{Ord,Eq} for pointers.

This commit is contained in:
Huon Wilson
2013-07-28 01:25:30 +10:00
parent 8407ec9fed
commit 88620c25f5
3 changed files with 49 additions and 2 deletions

View File

@@ -58,3 +58,15 @@ impl<'self, T: Ord> Ord for &'self T {
*(*self) > *(*other)
}
}
#[cfg(not(test))]
impl<'self, T: TotalOrd> TotalOrd for &'self T {
#[inline]
fn cmp(&self, other: & &'self T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<'self, T: TotalEq> TotalEq for &'self T {
#[inline]
fn equals(&self, other: & &'self T) -> bool { (**self).equals(*other) }
}

View File

@@ -12,7 +12,7 @@
use ptr::to_unsafe_ptr;
#[cfg(not(test))] use cmp::{Eq, Ord};
#[cfg(not(test))] use cmp::*;
pub static RC_MANAGED_UNIQUE : uint = (-2) as uint;
pub static RC_IMMORTAL : uint = 0x77777777;
@@ -71,6 +71,29 @@ impl<T:Ord> Ord for @mut T {
fn gt(&self, other: &@mut T) -> bool { *(*self) > *(*other) }
}
#[cfg(not(test))]
impl<T: TotalOrd> TotalOrd for @T {
#[inline]
fn cmp(&self, other: &@T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<T: TotalOrd> TotalOrd for @mut T {
#[inline]
fn cmp(&self, other: &@mut T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<T: TotalEq> TotalEq for @T {
#[inline]
fn equals(&self, other: &@T) -> bool { (**self).equals(*other) }
}
#[cfg(not(test))]
impl<T: TotalEq> TotalEq for @mut T {
#[inline]
fn equals(&self, other: &@mut T) -> bool { (**self).equals(*other) }
}
#[test]
fn test() {
let x = @3;

View File

@@ -10,7 +10,7 @@
//! Operations on unique pointer types
#[cfg(not(test))] use cmp::{Eq, Ord};
#[cfg(not(test))] use cmp::*;
#[cfg(not(test))]
impl<T:Eq> Eq for ~T {
@@ -31,3 +31,15 @@ impl<T:Ord> Ord for ~T {
#[inline]
fn gt(&self, other: &~T) -> bool { *(*self) > *(*other) }
}
#[cfg(not(test))]
impl<T: TotalOrd> TotalOrd for ~T {
#[inline]
fn cmp(&self, other: &~T) -> Ordering { (**self).cmp(*other) }
}
#[cfg(not(test))]
impl<T: TotalEq> TotalEq for ~T {
#[inline]
fn equals(&self, other: &~T) -> bool { (**self).equals(*other) }
}