vec: remove eachi

replaced by the `enumerate` method from std::iterator
This commit is contained in:
Daniel Micay 2013-06-17 16:37:11 -04:00
parent 62dc4e0d4c
commit cbad1da3db
6 changed files with 12 additions and 53 deletions

View file

@ -358,7 +358,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
// is the ending point, and * represents ANSI color codes.
for ProcRes.stderr.line_iter().advance |line| {
let mut was_expected = false;
for vec::eachi(expected_errors) |i, ee| {
for expected_errors.iter().enumerate().advance |(i, ee)| {
if !found_flags[i] {
debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s",
prefixes[i], ee.kind, ee.msg, line);

View file

@ -43,7 +43,7 @@ impl FnType {
let fnty = T_fn(atys, rty);
let llfn = decl(fnty);
for vec::eachi(self.attrs) |i, a| {
for self.attrs.iter().enumerate().advance |(i, a)| {
match *a {
option::Some(attr) => {
unsafe {
@ -100,7 +100,7 @@ impl FnType {
ret_def: bool,
llargbundle: ValueRef,
llretval: ValueRef) {
for vec::eachi(self.attrs) |i, a| {
for self.attrs.iter().enumerate().advance |(i, a)| {
match *a {
option::Some(attr) => {
unsafe {

View file

@ -225,7 +225,7 @@ pub fn store_environment(bcx: block,
// Copy expr values into boxed bindings.
let mut bcx = bcx;
for vec::eachi(bound_values) |i, bv| {
for bound_values.iter().enumerate().advance |(i, bv)| {
debug!("Copy %s into closure", bv.to_str(ccx));
if ccx.sess.asm_comments() {

View file

@ -462,7 +462,7 @@ pub fn trans_struct_drop(bcx: block,
// Drop the fields
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
for vec::eachi(field_tys) |i, fld| {
for field_tys.iter().enumerate().advance |(i, fld)| {
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
}

View file

@ -1427,21 +1427,6 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
return !broke;
}
/**
* Iterates over a vector's elements and indices
*
* Return true to continue, false to break.
*/
#[inline]
pub fn eachi<'r,T>(v: &'r [T], f: &fn(uint, v: &'r T) -> bool) -> bool {
let mut i = 0;
for each(v) |p| {
if !f(i, p) { return false; }
i += 1;
}
return true;
}
/**
* Iterate over all permutations of vector `v`.
*
@ -3259,17 +3244,6 @@ mod tests {
assert_eq!(i, 6);
}
#[test]
fn test_eachi() {
let mut i = 0;
for eachi([1, 2, 3]) |j, v| {
if i == 0 { assert!(*v == 1); }
assert_eq!(j + 1u, *v as uint);
i += *v;
}
assert_eq!(i, 6);
}
#[test]
fn test_each_ret_len0() {
let a0 : [int, .. 0] = [];
@ -4111,21 +4085,6 @@ mod tests {
};
}
#[test]
#[ignore(windows)]
#[should_fail]
fn test_eachi_fail() {
let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
let mut i = 0;
do eachi(v) |_i, _elt| {
if i == 2 {
fail!()
}
i += 0;
false
};
}
#[test]
#[ignore(windows)]
#[should_fail]

View file

@ -23,11 +23,11 @@ use std::uint;
use std::vec;
fn print_complements() {
let all = ~[Blue, Red, Yellow];
for vec::each(all) |aa| {
for vec::each(all) |bb| {
io::println(show_color(*aa) + " + " + show_color(*bb) +
" -> " + show_color(transform(*aa, *bb)));
let all = [Blue, Red, Yellow];
for all.iter().advance |aa| {
for all.iter().advance |bb| {
println(show_color(*aa) + " + " + show_color(*bb) +
" -> " + show_color(transform(*aa, *bb)));
}
}
}
@ -49,7 +49,7 @@ fn show_color(cc: color) -> ~str {
fn show_color_list(set: ~[color]) -> ~str {
let mut out = ~"";
for vec::eachi(set) |_ii, col| {
for set.iter().advance |col| {
out += " ";
out += show_color(*col);
}
@ -182,7 +182,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
}
// tell each creature to stop
for vec::eachi(to_creature) |_ii, to_one| {
for to_creature.iter().advance |to_one| {
to_one.send(None);
}