diff options
| author | Youngmin Yoo <youngmin.yoo@samsung.com> | 2013-05-13 11:10:12 +0900 |
|---|---|---|
| committer | Youngmin Yoo <youngmin.yoo@samsung.com> | 2013-05-13 13:55:09 +0900 |
| commit | 943b9d5dd9edacded3c763f399b4ea13fb2437bd (patch) | |
| tree | 6791ad17c6652ffb14e3cb3129085ddd78ae646b | |
| parent | 8291e36f184b2a72eaae8fa745759a09c17c8db8 (diff) | |
| download | rust-943b9d5dd9edacded3c763f399b4ea13fb2437bd.tar.gz rust-943b9d5dd9edacded3c763f399b4ea13fb2437bd.zip | |
Add vec.rs each2_mut function
| -rw-r--r-- | src/libcore/vec.rs | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 604f0297b64..9bfdec30577 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1681,8 +1681,8 @@ pub fn eachi_reverse<'r,T>(v: &'r [T], */ #[inline] pub fn _each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool { - assert!(len(v1) == len(v2)); - for uint::range(0u, len(v1)) |i| { + assert!(v1.len() == v2.len()); + for uint::range(0u, v1.len()) |i| { if !f(&v1[i], &v2[i]) { return false; } @@ -1700,6 +1700,35 @@ pub fn each2<U, T>(v1: &[U], v2: &[T], f: &fn(u: &U, t: &T) -> bool) -> bool { } /** + * + * Iterates over two vector with mutable. + * + * # Failure + * + * Both vectors must have the same length + */ +#[inline] +pub fn _each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) -> bool { + assert!(v1.len() == v2.len()); + for uint::range(0u, v1.len()) |i| { + if !f(&mut v1[i], &mut v2[i]) { + return false; + } + } + return true; +} + +#[cfg(stage0)] +pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) { + _each2_mut(v1, v2, f); +} + +#[cfg(not(stage0))] +pub fn each2_mut<U, T>(v1: &mut [U], v2: &mut [T], f: &fn(u: &mut U, t: &mut T) -> bool) -> bool { + _each2_mut(v1, v2, f) +} + +/** * Iterate over all permutations of vector `v`. * * Permutations are produced in lexicographic order with respect to the order |
