diff options
Diffstat (limited to 'src/libcore/vec.rs')
| -rw-r--r-- | src/libcore/vec.rs | 226 |
1 files changed, 114 insertions, 112 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 655db1c83d0..aed98f3573e 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -175,7 +175,7 @@ pub pure fn with_capacity<T>(capacity: uint) -> ~[T] { */ #[inline(always)] pub pure fn build_sized<A>(size: uint, - builder: fn(push: pure fn(v: A))) -> ~[A] { + builder: &fn(push: &pure fn(v: A))) -> ~[A] { let mut vec = with_capacity(size); builder(|x| unsafe { vec.push(x) }); vec @@ -192,7 +192,7 @@ pub pure fn build_sized<A>(size: uint, * onto the vector being constructed. */ #[inline(always)] -pub pure fn build<A>(builder: fn(push: pure fn(v: A))) -> ~[A] { +pub pure fn build<A>(builder: &fn(push: &pure fn(v: A))) -> ~[A] { build_sized(4, builder) } @@ -210,7 +210,7 @@ pub pure fn build<A>(builder: fn(push: pure fn(v: A))) -> ~[A] { */ #[inline(always)] pub pure fn build_sized_opt<A>(size: Option<uint>, - builder: fn(push: pure fn(v: A))) -> ~[A] { + builder: &fn(push: &pure fn(v: A))) -> ~[A] { build_sized(size.get_or_default(4), builder) } @@ -305,7 +305,7 @@ pub pure fn const_slice<T>(v: &r/[const T], /// Copies /// Split the vector `v` by applying each element against the predicate `f`. -pub fn split<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { +pub fn split<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -328,7 +328,7 @@ pub fn split<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { * Split the vector `v` by applying each element against the predicate `f` up * to `n` times. */ -pub fn splitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { +pub fn splitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -354,7 +354,7 @@ pub fn splitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { * Reverse split the vector `v` by applying each element against the predicate * `f`. */ -pub fn rsplit<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { +pub fn rsplit<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0) { return ~[] } @@ -378,7 +378,7 @@ pub fn rsplit<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[~[T]] { * Reverse split the vector `v` by applying each element against the predicate * `f` up to `n times. */ -pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { +pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: &fn(t: &T) -> bool) -> ~[~[T]] { let ln = len(v); if (ln == 0u) { return ~[] } @@ -405,7 +405,7 @@ pub fn rsplitn<T:Copy>(v: &[T], n: uint, f: fn(t: &T) -> bool) -> ~[~[T]] { * Partitions a vector into two new vectors: those that satisfies the * predicate, and those that do not. */ -pub fn partition<T>(v: ~[T], f: fn(&T) -> bool) -> (~[T], ~[T]) { +pub fn partition<T>(v: ~[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) { let mut lefts = ~[]; let mut rights = ~[]; @@ -426,7 +426,7 @@ pub fn partition<T>(v: ~[T], f: fn(&T) -> bool) -> (~[T], ~[T]) { * Partitions a vector into two new vectors: those that satisfies the * predicate, and those that do not. */ -pub pure fn partitioned<T:Copy>(v: &[T], f: fn(&T) -> bool) -> (~[T], ~[T]) { +pub pure fn partitioned<T:Copy>(v: &[T], f: &fn(&T) -> bool) -> (~[T], ~[T]) { let mut lefts = ~[]; let mut rights = ~[]; @@ -535,7 +535,7 @@ pub fn remove<T>(v: &mut ~[T], i: uint) -> T { v.pop() } -pub fn consume<T>(mut v: ~[T], f: fn(uint, v: T)) { +pub fn consume<T>(mut v: ~[T], f: &fn(uint, v: T)) { unsafe { do as_mut_buf(v) |p, ln| { for uint::range(0, ln) |i| { @@ -780,7 +780,7 @@ pub fn grow_set<T:Copy>(v: &mut ~[T], index: uint, initval: &T, val: T) { // Functional utilities /// Apply a function to each element of a vector and return the results -pub pure fn map<T, U>(v: &[T], f: fn(t: &T) -> U) -> ~[U] { +pub pure fn map<T, U>(v: &[T], f: &fn(t: &T) -> U) -> ~[U] { let mut result = with_capacity(len(v)); for each(v) |elem| { unsafe { @@ -790,7 +790,7 @@ pub pure fn map<T, U>(v: &[T], f: fn(t: &T) -> U) -> ~[U] { result } -pub fn map_consume<T, U>(v: ~[T], f: fn(v: T) -> U) -> ~[U] { +pub fn map_consume<T, U>(v: ~[T], f: &fn(v: T) -> U) -> ~[U] { let mut result = ~[]; do consume(v) |_i, x| { result.push(f(x)); @@ -799,7 +799,7 @@ pub fn map_consume<T, U>(v: ~[T], f: fn(v: T) -> U) -> ~[U] { } /// Apply a function to each element of a vector and return the results -pub pure fn mapi<T, U>(v: &[T], f: fn(uint, t: &T) -> U) -> ~[U] { +pub pure fn mapi<T, U>(v: &[T], f: &fn(uint, t: &T) -> U) -> ~[U] { let mut i = 0; do map(v) |e| { i += 1; @@ -811,7 +811,7 @@ pub pure fn mapi<T, U>(v: &[T], f: fn(uint, t: &T) -> U) -> ~[U] { * Apply a function to each element of a vector and return a concatenation * of each result vector */ -pub pure fn flat_map<T, U>(v: &[T], f: fn(t: &T) -> ~[U]) -> ~[U] { +pub pure fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U] { let mut result = ~[]; for each(v) |elem| { unsafe{ result.push_all_move(f(elem)); } } result @@ -819,7 +819,7 @@ pub pure fn flat_map<T, U>(v: &[T], f: fn(t: &T) -> ~[U]) -> ~[U] { /// Apply a function to each pair of elements and return the results pub pure fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U], - f: fn(t: &T, v: &U) -> V) -> ~[V] { + f: &fn(t: &T, v: &U) -> V) -> ~[V] { let v0_len = len(v0); if v0_len != len(v1) { fail!(); } let mut u: ~[V] = ~[]; @@ -833,7 +833,7 @@ pub pure fn map2<T:Copy,U:Copy,V>(v0: &[T], v1: &[U], pub fn filter_map<T, U>( v: ~[T], - f: fn(t: T) -> Option<U>) -> ~[U] + f: &fn(t: T) -> Option<U>) -> ~[U] { /*! * @@ -854,7 +854,7 @@ pub fn filter_map<T, U>( pub pure fn filter_mapped<T, U: Copy>( v: &[T], - f: fn(t: &T) -> Option<U>) -> ~[U] + f: &fn(t: &T) -> Option<U>) -> ~[U] { /*! * @@ -879,7 +879,7 @@ pub pure fn filter_mapped<T, U: Copy>( * Apply function `f` to each element of `v` and return a vector containing * only those elements for which `f` returned true. */ -pub fn filter<T>(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] { +pub fn filter<T>(v: ~[T], f: &fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; // FIXME (#4355 maybe): using v.consume here crashes // do v.consume |_, elem| { @@ -896,7 +896,7 @@ pub fn filter<T>(v: ~[T], f: fn(t: &T) -> bool) -> ~[T] { * Apply function `f` to each element of `v` and return a vector containing * only those elements for which `f` returned true. */ -pub pure fn filtered<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] { +pub pure fn filtered<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> ~[T] { let mut result = ~[]; for each(v) |elem| { if f(elem) { unsafe { result.push(*elem); } } @@ -907,7 +907,7 @@ pub pure fn filtered<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> ~[T] { /** * Like `filter()`, but in place. Preserves order of `v`. Linear time. */ -pub fn retain<T>(v: &mut ~[T], f: pure fn(t: &T) -> bool) { +pub fn retain<T>(v: &mut ~[T], f: &pure fn(t: &T) -> bool) { let len = v.len(); let mut deleted: uint = 0; @@ -963,7 +963,7 @@ pub pure fn connect<T:Copy>(v: &[~[T]], sep: &T) -> ~[T] { * ~~~ * */ -pub pure fn foldl<T, U>(z: T, v: &[U], p: fn(t: T, u: &U) -> T) -> T { +pub pure fn foldl<T, U>(z: T, v: &[U], p: &fn(t: T, u: &U) -> T) -> T { let mut accum = z; let mut i = 0; let l = v.len(); @@ -995,7 +995,7 @@ pub pure fn foldl<T, U>(z: T, v: &[U], p: fn(t: T, u: &U) -> T) -> T { * ~~~ * */ -pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(t: &T, u: U) -> U) -> U { +pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: &fn(t: &T, u: U) -> U) -> U { let mut accum = z; for rev_each(v) |elt| { accum = p(elt, accum); @@ -1008,7 +1008,7 @@ pub pure fn foldr<T, U: Copy>(v: &[T], z: U, p: fn(t: &T, u: U) -> U) -> U { * * If the vector contains no elements then false is returned. */ -pub pure fn any<T>(v: &[T], f: fn(t: &T) -> bool) -> bool { +pub pure fn any<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool { for each(v) |elem| { if f(elem) { return true; } } false } @@ -1019,7 +1019,7 @@ pub pure fn any<T>(v: &[T], f: fn(t: &T) -> bool) -> bool { * If the vectors contains no elements then false is returned. */ pub pure fn any2<T, U>(v0: &[T], v1: &[U], - f: fn(a: &T, b: &U) -> bool) -> bool { + f: &fn(a: &T, b: &U) -> bool) -> bool { let v0_len = len(v0); let v1_len = len(v1); let mut i = 0u; @@ -1035,7 +1035,7 @@ pub pure fn any2<T, U>(v0: &[T], v1: &[U], * * If the vector contains no elements then true is returned. */ -pub pure fn all<T>(v: &[T], f: fn(t: &T) -> bool) -> bool { +pub pure fn all<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool { for each(v) |elem| { if !f(elem) { return false; } } true } @@ -1045,7 +1045,7 @@ pub pure fn all<T>(v: &[T], f: fn(t: &T) -> bool) -> bool { * * If the vector contains no elements then true is returned. */ -pub pure fn alli<T>(v: &[T], f: fn(uint, t: &T) -> bool) -> bool { +pub pure fn alli<T>(v: &[T], f: &fn(uint, t: &T) -> bool) -> bool { for eachi(v) |i, elem| { if !f(i, elem) { return false; } } true } @@ -1056,7 +1056,7 @@ pub pure fn alli<T>(v: &[T], f: fn(uint, t: &T) -> bool) -> bool { * If the vectors are not the same size then false is returned. */ pub pure fn all2<T, U>(v0: &[T], v1: &[U], - f: fn(t: &T, u: &U) -> bool) -> bool { + f: &fn(t: &T, u: &U) -> bool) -> bool { let v0_len = len(v0); if v0_len != len(v1) { return false; } let mut i = 0u; @@ -1084,7 +1084,7 @@ pub pure fn count<T:Eq>(v: &[T], x: &T) -> uint { * When function `f` returns true then an option containing the element * is returned. If `f` matches no elements then none is returned. */ -pub pure fn find<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> { +pub pure fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> { find_between(v, 0u, len(v), f) } @@ -1096,7 +1096,7 @@ pub pure fn find<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> { * the element is returned. If `f` matches no elements then none is returned. */ pub pure fn find_between<T:Copy>(v: &[T], start: uint, end: uint, - f: fn(t: &T) -> bool) -> Option<T> { + f: &fn(t: &T) -> bool) -> Option<T> { position_between(v, start, end, f).map(|i| v[*i]) } @@ -1107,7 +1107,7 @@ pub pure fn find_between<T:Copy>(v: &[T], start: uint, end: uint, * `f` returns true then an option containing the element is returned. If `f` * matches no elements then none is returned. */ -pub pure fn rfind<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> { +pub pure fn rfind<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> { rfind_between(v, 0u, len(v), f) } @@ -1119,7 +1119,7 @@ pub pure fn rfind<T:Copy>(v: &[T], f: fn(t: &T) -> bool) -> Option<T> { * the element is returned. If `f` matches no elements then none is return. */ pub pure fn rfind_between<T:Copy>(v: &[T], start: uint, end: uint, - f: fn(t: &T) -> bool) -> Option<T> { + f: &fn(t: &T) -> bool) -> Option<T> { rposition_between(v, start, end, f).map(|i| v[*i]) } @@ -1135,7 +1135,7 @@ pub pure fn position_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> { * then an option containing the index is returned. If `f` matches no elements * then none is returned. */ -pub pure fn position<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> { +pub pure fn position<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> { position_between(v, 0u, len(v), f) } @@ -1147,7 +1147,7 @@ pub pure fn position<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> { * the index is returned. If `f` matches no elements then none is returned. */ pub pure fn position_between<T>(v: &[T], start: uint, end: uint, - f: fn(t: &T) -> bool) -> Option<uint> { + f: &fn(t: &T) -> bool) -> Option<uint> { fail_unless!(start <= end); fail_unless!(end <= len(v)); let mut i = start; @@ -1167,7 +1167,7 @@ pure fn rposition_elem<T:Eq>(v: &[T], x: &T) -> Option<uint> { * `f` returns true then an option containing the index is returned. If `f` * matches no elements then none is returned. */ -pub pure fn rposition<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> { +pub pure fn rposition<T>(v: &[T], f: &fn(t: &T) -> bool) -> Option<uint> { rposition_between(v, 0u, len(v), f) } @@ -1180,7 +1180,7 @@ pub pure fn rposition<T>(v: &[T], f: fn(t: &T) -> bool) -> Option<uint> { * returned. */ pub pure fn rposition_between<T>(v: &[T], start: uint, end: uint, - f: fn(t: &T) -> bool) -> Option<uint> { + f: &fn(t: &T) -> bool) -> Option<uint> { fail_unless!(start <= end); fail_unless!(end <= len(v)); let mut i = end; @@ -1334,7 +1334,7 @@ pub pure fn reversed<T:Copy>(v: &[const T]) -> ~[T] { * ~~~ */ #[inline(always)] -pub pure fn each<T>(v: &r/[T], f: fn(&r/T) -> bool) { +pub pure fn each<T>(v: &r/[T], f: &fn(&r/T) -> bool) { // ^^^^ // NB---this CANNOT be &[const T]! The reason // is that you are passing it to `f()` using @@ -1358,7 +1358,7 @@ pub pure fn each<T>(v: &r/[T], f: fn(&r/T) -> bool) { /// a vector with mutable contents and you would like /// to mutate the contents as you iterate. #[inline(always)] -pub fn each_mut<T>(v: &mut [T], f: fn(elem: &mut T) -> bool) { +pub fn each_mut<T>(v: &mut [T], f: &fn(elem: &mut T) -> bool) { let mut i = 0; let n = v.len(); while i < n { @@ -1372,7 +1372,7 @@ pub fn each_mut<T>(v: &mut [T], f: fn(elem: &mut T) -> bool) { /// Like `each()`, but for the case where you have a vector that *may or may /// not* have mutable contents. #[inline(always)] -pub pure fn each_const<T>(v: &[const T], f: fn(elem: &const T) -> bool) { +pub pure fn each_const<T>(v: &[const T], f: &fn(elem: &const T) -> bool) { let mut i = 0; let n = v.len(); while i < n { @@ -1389,7 +1389,7 @@ pub pure fn each_const<T>(v: &[const T], f: fn(elem: &const T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub pure fn eachi<T>(v: &r/[T], f: fn(uint, v: &r/T) -> bool) { +pub pure fn eachi<T>(v: &r/[T], f: &fn(uint, v: &r/T) -> bool) { let mut i = 0; for each(v) |p| { if !f(i, p) { return; } @@ -1403,7 +1403,7 @@ pub pure fn eachi<T>(v: &r/[T], f: fn(uint, v: &r/T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub pure fn rev_each<T>(v: &r/[T], blk: fn(v: &r/T) -> bool) { +pub pure fn rev_each<T>(v: &r/[T], blk: &fn(v: &r/T) -> bool) { rev_eachi(v, |_i, v| blk(v)) } @@ -1413,7 +1413,7 @@ pub pure fn rev_each<T>(v: &r/[T], blk: fn(v: &r/T) -> bool) { * Return true to continue, false to break. */ #[inline(always)] -pub pure fn rev_eachi<T>(v: &r/[T], blk: fn(i: uint, v: &r/T) -> bool) { +pub pure fn rev_eachi<T>(v: &r/[T], blk: &fn(i: uint, v: &r/T) -> bool) { let mut i = v.len(); while i > 0 { i -= 1; @@ -1431,7 +1431,7 @@ pub pure fn rev_eachi<T>(v: &r/[T], blk: fn(i: uint, v: &r/T) -> bool) { * Both vectors must have the same length */ #[inline] -pub pure fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) { +pub pure fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) { fail_unless!(len(v1) == len(v2)); for uint::range(0u, len(v1)) |i| { if !f(&v1[i], &v2[i]) { @@ -1450,7 +1450,7 @@ pub pure fn each2<U, T>(v1: &[U], v2: &[T], f: fn(u: &U, t: &T) -> bool) { * The total number of permutations produced is `len(v)!`. If `v` contains * repeated elements, then some permutations are repeated. */ -pub pure fn each_permutation<T:Copy>(v: &[T], put: fn(ts: &[T]) -> bool) { +pub pure fn each_permutation<T:Copy>(v: &[T], put: &fn(ts: &[T]) -> bool) { let ln = len(v); if ln <= 1 { put(v); @@ -1497,7 +1497,7 @@ pub pure fn windowed<TT:Copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] { #[inline(always)] pub pure fn as_imm_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */ - f: fn(*T, uint) -> U) -> U { + f: &fn(*T, uint) -> U) -> U { // NB---Do not change the type of s to `&[const T]`. This is // unsound. The reason is that we are going to create immutable pointers @@ -1516,7 +1516,7 @@ pub pure fn as_imm_buf<T,U>(s: &[T], /// Similar to `as_imm_buf` but passing a `*const T` #[inline(always)] pub pure fn as_const_buf<T,U>(s: &[const T], - f: fn(*const T, uint) -> U) -> U { + f: &fn(*const T, uint) -> U) -> U { unsafe { let v : *(*const T,uint) = @@ -1529,7 +1529,7 @@ pub pure fn as_const_buf<T,U>(s: &[const T], /// Similar to `as_imm_buf` but passing a `*mut T` #[inline(always)] pub pure fn as_mut_buf<T,U>(s: &mut [T], - f: fn(*mut T, uint) -> U) -> U { + f: &fn(*mut T, uint) -> U) -> U { unsafe { let v : *(*mut T,uint) = @@ -1721,13 +1721,13 @@ pub trait ImmutableVector<T> { pure fn initn(&self, n: uint) -> &self/[T]; pure fn last(&self) -> &self/T; pure fn last_opt(&self) -> Option<&self/T>; - pure fn foldr<U: Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U; - pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U]; - pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U]; - fn map_r<U>(&self, f: fn(x: &T) -> U) -> ~[U]; - pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool; - pure fn flat_map<U>(&self, f: fn(t: &T) -> ~[U]) -> ~[U]; - pure fn filter_mapped<U:Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U]; + pure fn foldr<U: Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U; + pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U]; + pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U]; + fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U]; + pure fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool; + pure fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]; + pure fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U]; } /// Extension methods for vectors @@ -1772,24 +1772,24 @@ impl<T> ImmutableVector<T> for &self/[T] { /// Reduce a vector from right to left #[inline] - pure fn foldr<U:Copy>(&self, z: U, p: fn(t: &T, u: U) -> U) -> U { + pure fn foldr<U:Copy>(&self, z: U, p: &fn(t: &T, u: U) -> U) -> U { foldr(*self, z, p) } /// Apply a function to each element of a vector and return the results #[inline] - pure fn map<U>(&self, f: fn(t: &T) -> U) -> ~[U] { map(*self, f) } + pure fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U] { map(*self, f) } /** * Apply a function to the index and value of each element in the vector * and return the results */ - pure fn mapi<U>(&self, f: fn(uint, t: &T) -> U) -> ~[U] { + pure fn mapi<U>(&self, f: &fn(uint, t: &T) -> U) -> ~[U] { mapi(*self, f) } #[inline] - fn map_r<U>(&self, f: fn(x: &T) -> U) -> ~[U] { + fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] { let mut r = ~[]; let mut i = 0; while i < self.len() { @@ -1804,7 +1804,7 @@ impl<T> ImmutableVector<T> for &self/[T] { * * If the vector is empty, true is returned. */ - pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool { + pure fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool { alli(*self, f) } /** @@ -1812,7 +1812,7 @@ impl<T> ImmutableVector<T> for &self/[T] { * of each result vector */ #[inline] - pure fn flat_map<U>(&self, f: fn(t: &T) -> ~[U]) -> ~[U] { + pure fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U] { flat_map(*self, f) } /** @@ -1822,15 +1822,15 @@ impl<T> ImmutableVector<T> for &self/[T] { * the resulting vector. */ #[inline] - pure fn filter_mapped<U:Copy>(&self, f: fn(t: &T) -> Option<U>) -> ~[U] { + pure fn filter_mapped<U:Copy>(&self, f: &fn(t: &T) -> Option<U>) -> ~[U] { filter_mapped(*self, f) } } pub trait ImmutableEqVector<T:Eq> { - pure fn position(&self, f: fn(t: &T) -> bool) -> Option<uint>; + pure fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint>; pure fn position_elem(&self, t: &T) -> Option<uint>; - pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option<uint>; + pure fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint>; pure fn rposition_elem(&self, t: &T) -> Option<uint>; } @@ -1843,7 +1843,7 @@ impl<T:Eq> ImmutableEqVector<T> for &self/[T] { * elements then none is returned. */ #[inline] - pure fn position(&self, f: fn(t: &T) -> bool) -> Option<uint> { + pure fn position(&self, f: &fn(t: &T) -> bool) -> Option<uint> { position(*self, f) } @@ -1861,7 +1861,7 @@ impl<T:Eq> ImmutableEqVector<T> for &self/[T] { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option<uint> { + pure fn rposition(&self, f: &fn(t: &T) -> bool) -> Option<uint> { rposition(*self, f) } @@ -1873,9 +1873,9 @@ impl<T:Eq> ImmutableEqVector<T> for &self/[T] { } pub trait ImmutableCopyableVector<T> { - pure fn filtered(&self, f: fn(&T) -> bool) -> ~[T]; - pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option<T>; - pure fn partitioned(&self, f: fn(&T) -> bool) -> (~[T], ~[T]); + pure fn filtered(&self, f: &fn(&T) -> bool) -> ~[T]; + pure fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T>; + pure fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]); } /// Extension methods for vectors @@ -1888,7 +1888,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &self/[T] { * containing only those elements for which `f` returned true. */ #[inline] - pure fn filtered(&self, f: fn(t: &T) -> bool) -> ~[T] { + pure fn filtered(&self, f: &fn(t: &T) -> bool) -> ~[T] { filtered(*self, f) } @@ -1900,7 +1900,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &self/[T] { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option<T> { + pure fn rfind(&self, f: &fn(t: &T) -> bool) -> Option<T> { rfind(*self, f) } @@ -1909,7 +1909,7 @@ impl<T:Copy> ImmutableCopyableVector<T> for &self/[T] { * those that do not. */ #[inline] - pure fn partitioned(&self, f: fn(&T) -> bool) -> (~[T], ~[T]) { + pure fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T]) { partitioned(*self, f) } } @@ -1924,10 +1924,10 @@ pub trait OwnedVector<T> { fn remove(&mut self, i: uint) -> T; fn swap_remove(&mut self, index: uint) -> T; fn truncate(&mut self, newlen: uint); - fn retain(&mut self, f: pure fn(t: &T) -> bool); - fn consume(self, f: fn(uint, v: T)); - fn filter(self, f: fn(t: &T) -> bool) -> ~[T]; - fn partition(self, f: pure fn(&T) -> bool) -> (~[T], ~[T]); + fn retain(&mut self, f: &pure fn(t: &T) -> bool); + fn consume(self, f: &fn(uint, v: T)); + fn filter(self, f: &fn(t: &T) -> bool) -> ~[T]; + fn partition(self, f: &pure fn(&T) -> bool) -> (~[T], ~[T]); fn grow_fn(&mut self, n: uint, op: iter::InitOp<T>); } @@ -1978,17 +1978,17 @@ impl<T> OwnedVector<T> for ~[T] { } #[inline] - fn retain(&mut self, f: pure fn(t: &T) -> bool) { + fn retain(&mut self, f: &pure fn(t: &T) -> bool) { retain(self, f); } #[inline] - fn consume(self, f: fn(uint, v: T)) { + fn consume(self, f: &fn(uint, v: T)) { consume(self, f) } #[inline] - fn filter(self, f: fn(&T) -> bool) -> ~[T] { + fn filter(self, f: &fn(&T) -> bool) -> ~[T] { filter(self, f) } @@ -1997,7 +1997,7 @@ impl<T> OwnedVector<T> for ~[T] { * those that do not. */ #[inline] - fn partition(self, f: fn(&T) -> bool) -> (~[T], ~[T]) { + fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T]) { partition(self, f) } @@ -2138,7 +2138,7 @@ pub mod raw { #[inline(always)] pub unsafe fn buf_as_slice<T,U>(p: *T, len: uint, - f: fn(v: &[T]) -> U) -> U { + f: &fn(v: &[T]) -> U) -> U { let pair = (p, len * sys::nonzero_size_of::<T>()); let v : *(&blk/[T]) = ::cast::reinterpret_cast(&addr_of(&pair)); @@ -2270,7 +2270,9 @@ pub mod bytes { impl<A> iter::BaseIter<A> for &self/[A] { #[inline(always)] - pure fn each(&self, blk: fn(v: &'self A) -> bool) { each(*self, blk) } + pub pure fn each(&self, blk: &fn(v: &'self A) -> bool) { + each(*self, blk) + } #[inline(always)] pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } } @@ -2278,7 +2280,7 @@ impl<A> iter::BaseIter<A> for &self/[A] { // FIXME(#4148): This should be redundant impl<A> iter::BaseIter<A> for ~[A] { #[inline(always)] - pure fn each(&self, blk: fn(v: &'self A) -> bool) { each(*self, blk) } + pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) } #[inline(always)] pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } } @@ -2286,31 +2288,31 @@ impl<A> iter::BaseIter<A> for ~[A] { // FIXME(#4148): This should be redundant impl<A> iter::BaseIter<A> for @[A] { #[inline(always)] - pure fn each(&self, blk: fn(v: &'self A) -> bool) { each(*self, blk) } + pure fn each(&self, blk: &fn(v: &'self A) -> bool) { each(*self, blk) } #[inline(always)] pure fn size_hint(&self) -> Option<uint> { Some(self.len()) } } impl<A> iter::ExtendedIter<A> for &self/[A] { - pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) { + pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) { iter::eachi(self, blk) } - pub pure fn all(&self, blk: fn(&A) -> bool) -> bool { + pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool { iter::all(self, blk) } - pub pure fn any(&self, blk: fn(&A) -> bool) -> bool { + pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool { iter::any(self, blk) } - pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B { + pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B { iter::foldl(self, b0, blk) } - pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> { + pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> { iter::position(self, f) } - pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] { + pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] { iter::map_to_vec(self, op) } - pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB) + pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B] { iter::flat_map_to_vec(self, op) } @@ -2318,25 +2320,25 @@ impl<A> iter::ExtendedIter<A> for &self/[A] { // FIXME(#4148): This should be redundant impl<A> iter::ExtendedIter<A> for ~[A] { - pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) { + pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) { iter::eachi(self, blk) } - pub pure fn all(&self, blk: fn(&A) -> bool) -> bool { + pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool { iter::all(self, blk) } - pub pure fn any(&self, blk: fn(&A) -> bool) -> bool { + pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool { iter::any(self, blk) } - pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B { + pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B { iter::foldl(self, b0, blk) } - pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> { + pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> { iter::position(self, f) } - pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] { + pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] { iter::map_to_vec(self, op) } - pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB) + pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B] { iter::flat_map_to_vec(self, op) } @@ -2344,25 +2346,25 @@ impl<A> iter::ExtendedIter<A> for ~[A] { // FIXME(#4148): This should be redundant impl<A> iter::ExtendedIter<A> for @[A] { - pub pure fn eachi(&self, blk: fn(uint, v: &A) -> bool) { + pub pure fn eachi(&self, blk: &fn(uint, v: &A) -> bool) { iter::eachi(self, blk) } - pub pure fn all(&self, blk: fn(&A) -> bool) -> bool { + pub pure fn all(&self, blk: &fn(&A) -> bool) -> bool { iter::all(self, blk) } - pub pure fn any(&self, blk: fn(&A) -> bool) -> bool { + pub pure fn any(&self, blk: &fn(&A) -> bool) -> bool { iter::any(self, blk) } - pub pure fn foldl<B>(&self, b0: B, blk: fn(&B, &A) -> B) -> B { + pub pure fn foldl<B>(&self, b0: B, blk: &fn(&B, &A) -> B) -> B { iter::foldl(self, b0, blk) } - pub pure fn position(&self, f: fn(&A) -> bool) -> Option<uint> { + pub pure fn position(&self, f: &fn(&A) -> bool) -> Option<uint> { iter::position(self, f) } - pure fn map_to_vec<B>(&self, op: fn(&A) -> B) -> ~[B] { + pure fn map_to_vec<B>(&self, op: &fn(&A) -> B) -> ~[B] { iter::map_to_vec(self, op) } - pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: fn(&A) -> IB) + pure fn flat_map_to_vec<B,IB:BaseIter<B>>(&self, op: &fn(&A) -> IB) -> ~[B] { iter::flat_map_to_vec(self, op) } @@ -2386,33 +2388,33 @@ impl<A:Eq> iter::EqIter<A> for @[A] { } impl<A:Copy> iter::CopyableIter<A> for &self/[A] { - pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] { + pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) } - pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> { + pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> { iter::find(self, f) } } // FIXME(#4148): This should be redundant impl<A:Copy> iter::CopyableIter<A> for ~[A] { - pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] { + pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) } - pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> { + pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> { iter::find(self, f) } } // FIXME(#4148): This should be redundant impl<A:Copy> iter::CopyableIter<A> for @[A] { - pure fn filter_to_vec(&self, pred: fn(&A) -> bool) -> ~[A] { + pure fn filter_to_vec(&self, pred: &fn(&A) -> bool) -> ~[A] { iter::filter_to_vec(self, pred) } pure fn to_vec(&self) -> ~[A] { iter::to_vec(self) } - pub pure fn find(&self, f: fn(&A) -> bool) -> Option<A> { + pub pure fn find(&self, f: &fn(&A) -> bool) -> Option<A> { iter::find(self, f) } } @@ -2435,7 +2437,7 @@ impl<A:Copy + Ord> iter::CopyableOrderedIter<A> for @[A] { } impl<A:Copy> iter::CopyableNonstrictIter<A> for &self/[A] { - pure fn each_val(&const self, f: fn(A) -> bool) { + pure fn each_val(&const self, f: &fn(A) -> bool) { let mut i = 0; while i < self.len() { if !f(copy self[i]) { break; } @@ -2446,7 +2448,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for &self/[A] { // FIXME(#4148): This should be redundant impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] { - pure fn each_val(&const self, f: fn(A) -> bool) { + pure fn each_val(&const self, f: &fn(A) -> bool) { let mut i = 0; while i < self.len() { if !f(copy self[i]) { break; } @@ -2457,7 +2459,7 @@ impl<A:Copy> iter::CopyableNonstrictIter<A> for ~[A] { // FIXME(#4148): This should be redundant impl<A:Copy> iter::CopyableNonstrictIter<A> for @[A] { - pure fn each_val(&const self, f: fn(A) -> bool) { + pure fn each_val(&const self, f: &fn(A) -> bool) { let mut i = 0; while i < self.len() { if !f(copy self[i]) { break; } |
