2012-07-04 23:53:12 +02:00
|
|
|
//! Operations on shared box types
|
2012-03-07 04:09:32 +01:00
|
|
|
|
2012-08-14 02:11:33 +02:00
|
|
|
// NB: transitionary, de-mode-ing.
|
|
|
|
#[forbid(deprecated_mode)];
|
|
|
|
#[forbid(deprecated_pattern)];
|
|
|
|
|
2012-09-04 20:12:17 +02:00
|
|
|
use cmp::{Eq, Ord};
|
2012-08-28 01:26:35 +02:00
|
|
|
|
2011-12-14 01:25:51 +01:00
|
|
|
export ptr_eq;
|
|
|
|
|
2012-06-25 05:18:18 +02:00
|
|
|
pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
2012-07-04 23:53:12 +02:00
|
|
|
//! Determine if two shared boxes point to the same object
|
2012-06-25 05:18:18 +02:00
|
|
|
unsafe { ptr::addr_of(*a) == ptr::addr_of(*b) }
|
2011-12-14 01:25:51 +01:00
|
|
|
}
|
2012-01-18 02:28:21 +01:00
|
|
|
|
2012-08-28 01:26:35 +02:00
|
|
|
impl<T:Eq> @const T : Eq {
|
|
|
|
pure fn eq(&&other: @const T) -> bool { *self == *other }
|
2012-09-07 21:06:02 +02:00
|
|
|
pure fn ne(&&other: @const T) -> bool { *self != *other }
|
2012-08-28 01:26:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T:Ord> @const T : Ord {
|
|
|
|
pure fn lt(&&other: @const T) -> bool { *self < *other }
|
2012-08-30 04:23:15 +02:00
|
|
|
pure fn le(&&other: @const T) -> bool { *self <= *other }
|
|
|
|
pure fn ge(&&other: @const T) -> bool { *self >= *other }
|
|
|
|
pure fn gt(&&other: @const T) -> bool { *self > *other }
|
2012-08-28 01:26:35 +02:00
|
|
|
}
|
|
|
|
|
2012-01-18 02:28:21 +01:00
|
|
|
#[test]
|
|
|
|
fn test() {
|
|
|
|
let x = @3;
|
|
|
|
let y = @3;
|
|
|
|
assert (ptr_eq::<int>(x, x));
|
|
|
|
assert (ptr_eq::<int>(y, y));
|
|
|
|
assert (!ptr_eq::<int>(x, y));
|
|
|
|
assert (!ptr_eq::<int>(y, x));
|
|
|
|
}
|