vec: remove eachi
replaced by the `enumerate` method from std::iterator
This commit is contained in:
@@ -358,7 +358,7 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
|
|||||||
// is the ending point, and * represents ANSI color codes.
|
// is the ending point, and * represents ANSI color codes.
|
||||||
for ProcRes.stderr.line_iter().advance |line| {
|
for ProcRes.stderr.line_iter().advance |line| {
|
||||||
let mut was_expected = false;
|
let mut was_expected = false;
|
||||||
for vec::eachi(expected_errors) |i, ee| {
|
for expected_errors.iter().enumerate().advance |(i, ee)| {
|
||||||
if !found_flags[i] {
|
if !found_flags[i] {
|
||||||
debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s",
|
debug!("prefix=%s ee.kind=%s ee.msg=%s line=%s",
|
||||||
prefixes[i], ee.kind, ee.msg, line);
|
prefixes[i], ee.kind, ee.msg, line);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ impl FnType {
|
|||||||
let fnty = T_fn(atys, rty);
|
let fnty = T_fn(atys, rty);
|
||||||
let llfn = decl(fnty);
|
let llfn = decl(fnty);
|
||||||
|
|
||||||
for vec::eachi(self.attrs) |i, a| {
|
for self.attrs.iter().enumerate().advance |(i, a)| {
|
||||||
match *a {
|
match *a {
|
||||||
option::Some(attr) => {
|
option::Some(attr) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -100,7 +100,7 @@ impl FnType {
|
|||||||
ret_def: bool,
|
ret_def: bool,
|
||||||
llargbundle: ValueRef,
|
llargbundle: ValueRef,
|
||||||
llretval: ValueRef) {
|
llretval: ValueRef) {
|
||||||
for vec::eachi(self.attrs) |i, a| {
|
for self.attrs.iter().enumerate().advance |(i, a)| {
|
||||||
match *a {
|
match *a {
|
||||||
option::Some(attr) => {
|
option::Some(attr) => {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ pub fn store_environment(bcx: block,
|
|||||||
|
|
||||||
// Copy expr values into boxed bindings.
|
// Copy expr values into boxed bindings.
|
||||||
let mut bcx = bcx;
|
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));
|
debug!("Copy %s into closure", bv.to_str(ccx));
|
||||||
|
|
||||||
if ccx.sess.asm_comments() {
|
if ccx.sess.asm_comments() {
|
||||||
|
|||||||
@@ -462,7 +462,7 @@ pub fn trans_struct_drop(bcx: block,
|
|||||||
|
|
||||||
// Drop the fields
|
// Drop the fields
|
||||||
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
|
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);
|
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
|
||||||
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
|
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1427,21 +1427,6 @@ pub fn each<'r,T>(v: &'r [T], f: &fn(&'r T) -> bool) -> bool {
|
|||||||
return !broke;
|
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`.
|
* Iterate over all permutations of vector `v`.
|
||||||
*
|
*
|
||||||
@@ -3259,17 +3244,6 @@ mod tests {
|
|||||||
assert_eq!(i, 6);
|
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]
|
#[test]
|
||||||
fn test_each_ret_len0() {
|
fn test_each_ret_len0() {
|
||||||
let a0 : [int, .. 0] = [];
|
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]
|
#[test]
|
||||||
#[ignore(windows)]
|
#[ignore(windows)]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ use std::uint;
|
|||||||
use std::vec;
|
use std::vec;
|
||||||
|
|
||||||
fn print_complements() {
|
fn print_complements() {
|
||||||
let all = ~[Blue, Red, Yellow];
|
let all = [Blue, Red, Yellow];
|
||||||
for vec::each(all) |aa| {
|
for all.iter().advance |aa| {
|
||||||
for vec::each(all) |bb| {
|
for all.iter().advance |bb| {
|
||||||
io::println(show_color(*aa) + " + " + show_color(*bb) +
|
println(show_color(*aa) + " + " + show_color(*bb) +
|
||||||
" -> " + show_color(transform(*aa, *bb)));
|
" -> " + show_color(transform(*aa, *bb)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ fn show_color(cc: color) -> ~str {
|
|||||||
|
|
||||||
fn show_color_list(set: ~[color]) -> ~str {
|
fn show_color_list(set: ~[color]) -> ~str {
|
||||||
let mut out = ~"";
|
let mut out = ~"";
|
||||||
for vec::eachi(set) |_ii, col| {
|
for set.iter().advance |col| {
|
||||||
out += " ";
|
out += " ";
|
||||||
out += show_color(*col);
|
out += show_color(*col);
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// tell each creature to stop
|
// tell each creature to stop
|
||||||
for vec::eachi(to_creature) |_ii, to_one| {
|
for to_creature.iter().advance |to_one| {
|
||||||
to_one.send(None);
|
to_one.send(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user