libstd: Implement a Sort trait.

This depends on the previous fix to not assert.
This commit is contained in:
Patrick Walton 2012-09-03 15:58:01 -07:00
parent 5573ad723f
commit 8f840f9ea0
1 changed files with 9 additions and 0 deletions

View File

@ -9,6 +9,7 @@ export le;
export merge_sort;
export quick_sort;
export quick_sort3;
export Sort;
type le<T> = pure fn(v1: &T, v2: &T) -> bool;
@ -160,6 +161,14 @@ fn quick_sort3<T: copy Ord Eq>(arr: &[mut T]) {
qsort3(arr, 0, (arr.len() - 1) as int);
}
trait Sort {
fn qsort(self);
}
impl<T: copy Ord Eq> &[mut T] : Sort {
fn qsort(self) { quick_sort3(self); }
}
#[cfg(test)]
mod test_qsort3 {
fn check_sort(v1: &[mut int], v2: &[mut int]) {