use core::kinds::{Copy, Sized};
use core::mem::size_of;
use core::mem;
+use core::ops::FnMut;
use core::prelude::{Clone, Greater, Iterator, IteratorExt, Less, None, Option};
use core::prelude::{Ord, Ordering, RawPtr, Some, range};
use core::ptr;
/// Partitions the vector into two vectors `(a, b)`, where all
/// elements of `a` satisfy `f` and all elements of `b` do not.
- fn partitioned(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>);
+ fn partitioned<F>(&self, f: F) -> (Vec<T>, Vec<T>) where F: FnMut(&T) -> bool;
/// Creates an iterator that yields every possible permutation of the
/// vector in succession.
#[inline]
- fn partitioned(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>) {
+ fn partitioned<F>(&self, mut f: F) -> (Vec<T>, Vec<T>) where F: FnMut(&T) -> bool {
let mut lefts = Vec::new();
let mut rights = Vec::new();
}
-fn insertion_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
+fn insertion_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Ordering {
let len = v.len() as int;
let buf_v = v.as_mut_ptr();
}
}
-fn merge_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
+fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Ordering {
// warning: this wildly uses unsafe.
static BASE_INSERTION: uint = 32;
static LARGE_INSERTION: uint = 16;
/// v.sort_by(|a, b| b.cmp(a));
/// assert!(v == [5, 4, 3, 2, 1]);
/// ```
- fn sort_by(&mut self, compare: |&T, &T| -> Ordering);
+ fn sort_by<F>(&mut self, compare: F) where F: FnMut(&T, &T) -> Ordering;
/// Consumes `src` and moves as many elements as it can into `self`
/// from the range [start,end).
impl<T> SliceAllocPrelude<T> for [T] {
#[inline]
- fn sort_by(&mut self, compare: |&T, &T| -> Ordering) {
+ fn sort_by<F>(&mut self, compare: F) where F: FnMut(&T, &T) -> Ordering {
merge_sort(self, compare)
}