]> git.lizzy.rs Git - rust.git/commitdiff
std: remove {all*,any*,count} in favour of iterators
authorHuon Wilson <dbau.pp+github@gmail.com>
Sat, 8 Jun 2013 04:07:55 +0000 (14:07 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Sat, 8 Jun 2013 16:22:23 +0000 (02:22 +1000)
12 files changed:
src/libextra/par.rs
src/librustc/middle/trans/_match.rs
src/librustc/middle/trans/monomorphize.rs
src/librustc/middle/ty.rs
src/librustc/middle/typeck/check/mod.rs
src/libstd/iterator.rs
src/libstd/str.rs
src/libstd/vec.rs
src/test/bench/graph500-bfs.rs
src/test/run-pass/block-arg.rs
src/test/run-pass/ret-break-cont-in-block.rs
src/test/run-pass/test-ignore-cfg.rs

index 49696a5fa25c74135d6f5262ca6949650f8d384f..23b7cdc09974780cc5fee860b3e272ac52e71232 100644 (file)
@@ -10,6 +10,7 @@
 
 use core::prelude::*;
 
+use core::iterator::IteratorUtil;
 use core::cast;
 use core::ptr;
 use core::sys;
@@ -122,25 +123,24 @@ pub fn alli<A:Copy + Owned>(
     xs: &[A],
     fn_factory: &fn() -> ~fn(uint, &A) -> bool) -> bool
 {
-    do vec::all(map_slices(xs, || {
+    let mapped = map_slices(xs, || {
         let f = fn_factory();
         let result: ~fn(uint, &[A]) -> bool = |base, slice| {
-            vec::alli(slice, |i, x| {
-                f(i + base, x)
-            })
+            slice.iter().enumerate().all(|(i, x)| f(i + base, x))
         };
         result
-    })) |x| { *x }
+    });
+    mapped.iter().all(|&x| x)
 }
 
 /// Returns true if the function holds for any elements in the vector.
 pub fn any<A:Copy + Owned>(
     xs: &[A],
     fn_factory: &fn() -> ~fn(&A) -> bool) -> bool {
-    do vec::any(map_slices(xs, || {
+    let mapped = map_slices(xs, || {
         let f = fn_factory();
-        let result: ~fn(uint, &[A]) -> bool =
-            |_, slice| vec::any(slice, |x| f(x));
+        let result: ~fn(uint, &[A]) -> bool = |_, slice| slice.iter().any(f);
         result
-    })) |x| { *x }
+    });
+    mapped.iter().any(|&x| x)
 }
index a42e1cd0647926d711d0b3b22530c118b59a30c0..49db0ee7bd30af73891c106678c270dbc1b0b801 100644 (file)
 use middle::ty;
 use util::common::indenter;
 
+use core::iterator::IteratorUtil;
 use core::hashmap::HashMap;
 use core::vec;
 use syntax::ast;
@@ -798,7 +799,7 @@ pub fn enter_region<'r>(bcx: block,
 pub fn get_options(bcx: block, m: &[@Match], col: uint) -> ~[Opt] {
     let ccx = bcx.ccx();
     fn add_to_set(tcx: ty::ctxt, set: &mut ~[Opt], val: Opt) {
-        if set.any(|l| opt_eq(tcx, l, &val)) {return;}
+        if set.iter().any(|l| opt_eq(tcx, l, &val)) {return;}
         set.push(val);
     }
 
@@ -965,7 +966,7 @@ pub fn collect_record_or_struct_fields(bcx: block,
     fn extend(idents: &mut ~[ast::ident], field_pats: &[ast::field_pat]) {
         for field_pats.each |field_pat| {
             let field_ident = field_pat.ident;
-            if !vec::any(*idents, |x| *x == field_ident) {
+            if !idents.iter().any(|x| *x == field_ident) {
                 idents.push(field_ident);
             }
         }
@@ -976,11 +977,11 @@ pub fn pats_require_rooting(bcx: block,
                             m: &[@Match],
                             col: uint)
                          -> bool {
-    vec::any(m, |br| {
+    do m.iter().any |br| {
         let pat_id = br.pats[col].id;
         let key = root_map_key {id: pat_id, derefs: 0u };
         bcx.ccx().maps.root_map.contains_key(&key)
-    })
+    }
 }
 
 pub fn root_pats_as_necessary(mut bcx: block,
@@ -1005,12 +1006,12 @@ pub fn root_pats_as_necessary(mut bcx: block,
 // matches may be wildcards like _ or identifiers).
 macro_rules! any_pat (
     ($m:expr, $pattern:pat) => (
-        vec::any($m, |br| {
+        do ($m).iter().any |br| {
             match br.pats[col].node {
                 $pattern => true,
                 _ => false
             }
-        })
+        }
     )
 )
 
@@ -1031,7 +1032,7 @@ pub fn any_tup_pat(m: &[@Match], col: uint) -> bool {
 }
 
 pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool {
-    vec::any(m, |br| {
+    do m.iter().any |br| {
         let pat = br.pats[col];
         match pat.node {
             ast::pat_enum(_, Some(_)) => {
@@ -1043,7 +1044,7 @@ pub fn any_tuple_struct_pat(bcx: block, m: &[@Match], col: uint) -> bool {
             }
             _ => false
         }
-    })
+    }
 }
 
 pub type mk_fail = @fn() -> BasicBlockRef;
index 062f72b6feba63b87fcf99fa2e5ffca72c26f0ba..169cd294b43c4324d837e0d7b889c74942f22cd7 100644 (file)
@@ -32,6 +32,7 @@
 use middle::typeck;
 use util::ppaux::{Repr,ty_to_str};
 
+use core::iterator::IteratorUtil;
 use core::vec;
 use syntax::ast;
 use syntax::ast_map;
@@ -75,7 +76,7 @@ pub fn monomorphic_fn(ccx: @CrateContext,
     let param_uses = type_use::type_uses_for(ccx, fn_id, substs.len());
     let hash_id = make_mono_id(ccx, fn_id, substs, vtables, impl_did_opt,
                                Some(param_uses));
-    if vec::any(hash_id.params,
+    if hash_id.params.iter().any(
                 |p| match *p { mono_precise(_, _) => false, _ => true }) {
         must_cast = true;
     }
index 8e2691c8a27a1ecd89b5a49ad20b675edfcfabe8..e8501904c6f25549d278cda4b04f7005c015eba3 100644 (file)
@@ -27,6 +27,7 @@
 use util::common::{indenter};
 use util::enum_set::{EnumSet, CLike};
 
+use core::iterator::IteratorUtil;
 use core::cast;
 use core::cmp;
 use core::hashmap::{HashMap, HashSet};
@@ -2355,8 +2356,8 @@ fn subtypes_require(cx: ctxt, seen: &mut ~[def_id],
 
           ty_struct(did, ref substs) => {
               seen.push(did);
-              let r = vec::any(struct_fields(cx, did, substs),
-                               |f| type_requires(cx, seen, r_ty, f.mt.ty));
+              let fields = struct_fields(cx, did, substs);
+              let r = fields.iter().any(|f| type_requires(cx, seen, r_ty, f.mt.ty));
               seen.pop();
             r
           }
@@ -2372,12 +2373,12 @@ fn subtypes_require(cx: ctxt, seen: &mut ~[def_id],
             ty_enum(did, ref substs) => {
                 seen.push(did);
                 let vs = enum_variants(cx, did);
-                let r = vec::len(*vs) > 0u && vec::all(*vs, |variant| {
-                    vec::any(variant.args, |aty| {
+                let r = vec::len(*vs) > 0u && do vs.iter().all |variant| {
+                    do variant.args.iter().any |aty| {
                         let sty = subst(cx, substs, *aty);
                         type_requires(cx, seen, r_ty, sty)
-                    })
-                });
+                    }
+                };
                 seen.pop();
                 r
             }
@@ -2519,11 +2520,12 @@ pub fn type_is_pod(cx: ctxt, ty: t) -> bool {
       ty_param(_) => result = false,
       ty_opaque_closure_ptr(_) => result = true,
       ty_struct(did, ref substs) => {
-        result = vec::all(lookup_struct_fields(cx, did), |f| {
+        let fields = lookup_struct_fields(cx, did);
+        result = do fields.iter().all |f| {
             let fty = ty::lookup_item_type(cx, f.id);
             let sty = subst(cx, substs, fty.ty);
             type_is_pod(cx, sty)
-        });
+        };
       }
 
       ty_estr(vstore_slice(*)) | ty_evec(_, vstore_slice(*)) => {
@@ -2569,7 +2571,7 @@ pub fn type_is_c_like_enum(cx: ctxt, ty: t) -> bool {
             if variants.len() == 0 {
                 false
             } else {
-                variants.all(|v| v.args.len() == 0)
+                variants.iter().all(|v| v.args.len() == 0)
             }
         }
         _ => false
index 9241fb6da908de2cc7fb995e15628e1100c470f4..9eb5f8159545efc270fa7bef855a5f920cc4c2c0 100644 (file)
@@ -3065,7 +3065,7 @@ pub fn check_simd(tcx: ty::ctxt, sp: span, id: ast::node_id) {
                 return;
             }
             let e = ty::lookup_field_type(tcx, did, fields[0].id, substs);
-            if !vec::all(fields,
+            if !fields.iter().all(
                          |f| ty::lookup_field_type(tcx, did, f.id, substs) == e) {
                 tcx.sess.span_err(sp, "SIMD vector should be homogeneous");
                 return;
index 4ed82f63b394c62db1b597ba8f5e5f0f93c5ec99..309e207eaaa8855d875400cf80efc195fbfc4463 100644 (file)
@@ -326,7 +326,7 @@ fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
     /// assert!(a.iter().all(|&x| *x > 0));
     /// assert!(!a.iter().all(|&x| *x > 2));
     /// ~~~
-    fn all(&mut self, f: &fn(&A) -> bool) -> bool;
+    fn all(&mut self, f: &fn(A) -> bool) -> bool;
 
     /// Tests whether any element of an iterator satisfies the specified
     /// predicate.
@@ -341,7 +341,7 @@ fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option<B>)
     /// assert!(it.any(|&x| *x == 3));
     /// assert!(!it.any(|&x| *x == 3));
     /// ~~~
-    fn any(&mut self, f: &fn(&A) -> bool) -> bool;
+    fn any(&mut self, f: &fn(A) -> bool) -> bool;
 }
 
 /// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also
@@ -462,14 +462,14 @@ fn fold<B>(&mut self, init: B, f: &fn(B, A) -> B) -> B {
     fn count(&mut self) -> uint { self.fold(0, |cnt, _x| cnt + 1) }
 
     #[inline(always)]
-    fn all(&mut self, f: &fn(&A) -> bool) -> bool {
-        for self.advance |x| { if !f(&x) { return false; } }
+    fn all(&mut self, f: &fn(A) -> bool) -> bool {
+        for self.advance |x| { if !f(x) { return false; } }
         return true;
     }
 
     #[inline(always)]
-    fn any(&mut self, f: &fn(&A) -> bool) -> bool {
-        for self.advance |x| { if f(&x) { return true; } }
+    fn any(&mut self, f: &fn(A) -> bool) -> bool {
+        for self.advance |x| { if f(x) { return true; } }
         return false;
     }
 }
@@ -1080,18 +1080,18 @@ fn test_collect() {
     #[test]
     fn test_all() {
         let v = ~&[1, 2, 3, 4, 5];
-        assert!(v.iter().all(|&x| *x < 10));
+        assert!(v.iter().all(|&x| x < 10));
         assert!(!v.iter().all(|&x| x.is_even()));
-        assert!(!v.iter().all(|&x| *x > 100));
+        assert!(!v.iter().all(|&x| x > 100));
         assert!(v.slice(0, 0).iter().all(|_| fail!()));
     }
 
     #[test]
     fn test_any() {
         let v = ~&[1, 2, 3, 4, 5];
-        assert!(v.iter().any(|&x| *x < 10));
+        assert!(v.iter().any(|&x| x < 10));
         assert!(v.iter().any(|&x| x.is_even()));
-        assert!(!v.iter().any(|&x| *x > 100));
+        assert!(!v.iter().any(|&x| x > 100));
         assert!(!v.slice(0, 0).iter().any(|_| fail!()));
     }
 }
index 8dc546ec4f855cbbd2ad992b4a3dd7d07a385573..d0345a3953e6172f8d8ea1c7f51a883367b65031 100644 (file)
@@ -2883,6 +2883,7 @@ fn next(&mut self) -> Option<char> {
 
 #[cfg(test)]
 mod tests {
+    use iterator::IteratorUtil;
     use container::Container;
     use char;
     use option::Some;
@@ -2977,7 +2978,7 @@ fn t(s: &str, c: char, u: &[~str]) {
             let mut v = ~[];
             for each_split_char(s, c) |s| { v.push(s.to_owned()) }
             debug!("split_byte to: %?", v);
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         t("abc.hello.there", '.', [~"abc", ~"hello", ~"there"]);
         t(".hello.there", '.', [~"", ~"hello", ~"there"]);
@@ -2995,7 +2996,7 @@ fn t(s: &str, c: char, u: &[~str]) {
             let mut v = ~[];
             for each_split_char(s, c) |s| { v.push(s.to_owned()) }
             debug!("split_byte to: %?", v);
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         let data = "ประเทศไทย中华Việt Nam";
         t(data, 'V', [~"ประเทศไทย中华", ~"iệt Nam"]);
@@ -3010,7 +3011,7 @@ fn t(s: &str, c: char, n: uint, u: &[~str]) {
             for each_splitn_char(s, c, n) |s| { v.push(s.to_owned()) }
             debug!("split_byte to: %?", v);
             debug!("comparing vs. %?", u);
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         t("abc.hello.there", '.', 0u, [~"abc.hello.there"]);
         t("abc.hello.there", '.', 1u, [~"abc", ~"hello.there"]);
@@ -3037,7 +3038,7 @@ fn t(s: &str, c: char, n: uint, u: &[~str]) {
             for each_splitn_char(s, c, n) |s| { v.push(s.to_owned()) }
             debug!("split_byte to: %?", v);
             debug!("comparing vs. %?", u);
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
 
         t("ประเทศไทย中华Việt Nam", '华', 1u, [~"ประเทศไทย中", ~"Việt Nam"]);
@@ -3055,7 +3056,7 @@ fn t(s: &str, c: char, n: uint, u: &[~str]) {
             for each_splitn_char(s, c, n) |s| { v.push(s.to_owned()) }
             debug!("split_byte to: %?", v);
             debug!("comparing vs. %?", u);
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         let data = "ประเทศไทย中华Việt Nam";
         t(data, 'V', 1u, [~"ประเทศไทย中华", ~"iệt Nam"]);
@@ -3069,7 +3070,7 @@ fn t(s: &str, c: char, u: &[~str]) {
             let mut v = ~[];
             for each_split_char_no_trailing(s, c) |s| { v.push(s.to_owned()) }
             debug!("split_byte to: %?", v);
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         t("abc.hello.there", '.', [~"abc", ~"hello", ~"there"]);
         t(".hello.there", '.', [~"", ~"hello", ~"there"]);
@@ -3088,7 +3089,7 @@ fn t(s: &str, c: char, u: &[~str]) {
             let mut v = ~[];
             for each_split_char_no_trailing(s, c) |s| { v.push(s.to_owned()) }
             debug!("split_byte to: %?", v);
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         let data = "ประเทศไทย中华Việt Nam";
         t(data, 'V', [~"ประเทศไทย中华", ~"iệt Nam"]);
@@ -3100,7 +3101,7 @@ fn test_split_str() {
         fn t<'a>(s: &str, sep: &'a str, u: &[~str]) {
             let mut v = ~[];
             for each_split_str(s, sep) |s| { v.push(s.to_owned()) }
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         t("--1233345--", "12345", [~"--1233345--"]);
         t("abc::hello::there", "::", [~"abc", ~"hello", ~"there"]);
@@ -3124,7 +3125,7 @@ fn test_split() {
         fn t(s: &str, sepf: &fn(char) -> bool, u: &[~str]) {
             let mut v = ~[];
             for each_split(s, sepf) |s| { v.push(s.to_owned()) }
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
 
         t("ประเทศไทย中华Việt Nam", |cc| cc == '华', [~"ประเทศไทย中", ~"Việt Nam"]);
@@ -3140,7 +3141,7 @@ fn test_split_no_trailing() {
         fn t(s: &str, sepf: &fn(char) -> bool, u: &[~str]) {
             let mut v = ~[];
             for each_split_no_trailing(s, sepf) |s| { v.push(s.to_owned()) }
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
 
         t("ประเทศไทย中华Việt Nam", |cc| cc == '华', [~"ประเทศไทย中", ~"Việt Nam"]);
@@ -3159,7 +3160,7 @@ fn test_lines() {
         fn t(s: &str, f: &fn(&str, &fn(&str) -> bool) -> bool, u: &[~str]) {
             let mut v = ~[];
             for f(s) |s| { v.push(s.to_owned()) }
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
 
         t(lf, each_line, [~"", ~"Mary had a little lamb", ~"Little lamb"]);
@@ -3179,7 +3180,7 @@ fn test_words() {
         fn t(s: &str, f: &fn(&str, &fn(&str) -> bool) -> bool, u: &[~str]) {
             let mut v = ~[];
             for f(s) |s| { v.push(s.to_owned()) }
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         let data = "\nMary had a little lamb\nLittle lamb\n";
 
@@ -3193,7 +3194,7 @@ fn test_split_within() {
         fn t(s: &str, i: uint, u: &[~str]) {
             let mut v = ~[];
             for each_split_within(s, i) |s| { v.push(s.to_owned()) }
-            assert!(vec::all2(v, u, |a,b| a == b));
+            assert!(v.iter().zip(u.iter()).all(|(a,b)| a == b));
         }
         t("", 0, []);
         t("", 15, []);
index f34e1a91b69a7dd9f94bc37edd32498c099e9f6c..29f2dba77a6e9d819ba3f83c9b139c3228771b1c 100644 (file)
@@ -1124,80 +1124,12 @@ pub fn foldr<'a, T, U>(v: &'a [T], mut z: U, p: &fn(t: &'a T, u: U) -> U) -> U {
     return z;
 }
 
-/**
- * Return true if a predicate matches any elements
- *
- * If the vector contains no elements then false is returned.
- */
-pub fn any<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
-    for each(v) |elem| { if f(elem) { return true; } }
-    false
-}
-
-/**
- * Return true if a predicate matches any elements in both vectors.
- *
- * If the vectors contains no elements then false is returned.
- */
-pub fn any2<T, U>(v0: &[T], v1: &[U],
-                   f: &fn(a: &T, b: &U) -> bool) -> bool {
-    let v0_len = len(v0);
-    let v1_len = len(v1);
-    let mut i = 0u;
-    while i < v0_len && i < v1_len {
-        if f(&v0[i], &v1[i]) { return true; };
-        i += 1u;
-    }
-    false
-}
-
-/**
- * Return true if a predicate matches all elements
- *
- * If the vector contains no elements then true is returned.
- */
-pub fn all<T>(v: &[T], f: &fn(t: &T) -> bool) -> bool {
-    for each(v) |elem| { if !f(elem) { return false; } }
-    true
-}
-
-/**
- * Return true if a predicate matches all elements
- *
- * If the vector contains no elements then true is returned.
- */
-pub fn alli<T>(v: &[T], f: &fn(uint, t: &T) -> bool) -> bool {
-    for eachi(v) |i, elem| { if !f(i, elem) { return false; } }
-    true
-}
-
-/**
- * Return true if a predicate matches all elements in both vectors.
- *
- * If the vectors are not the same size then false is returned.
- */
-pub fn all2<T, U>(v0: &[T], v1: &[U],
-                   f: &fn(t: &T, u: &U) -> bool) -> bool {
-    let v0_len = len(v0);
-    if v0_len != len(v1) { return false; }
-    let mut i = 0u;
-    while i < v0_len { if !f(&v0[i], &v1[i]) { return false; }; i += 1u; }
-    true
-}
-
 /// Return true if a vector contains an element with the given value
 pub fn contains<T:Eq>(v: &[T], x: &T) -> bool {
     for each(v) |elt| { if *x == *elt { return true; } }
     false
 }
 
-/// Returns the number of elements that are equal to a given value
-pub fn count<T:Eq>(v: &[T], x: &T) -> uint {
-    let mut cnt = 0u;
-    for each(v) |elt| { if *x == *elt { cnt += 1u; } }
-    cnt
-}
-
 /**
  * Search for the first element that matches a given predicate
  *
@@ -2074,7 +2006,7 @@ fn map_r<U>(&self, f: &fn(x: &T) -> U) -> ~[U] {
      *     If the vector is empty, true is returned.
      */
     fn alli(&self, f: &fn(uint, t: &T) -> bool) -> bool {
-        alli(*self, f)
+        self.iter().enumerate().all(|(i, t)| f(i,t))
     }
     /**
      * Apply a function to each element of a vector and return a concatenation
@@ -3558,33 +3490,6 @@ fn test_each_permutation() {
             ~[~[5,2,0],~[5,0,2],~[2,5,0],~[2,0,5],~[0,5,2],~[0,2,5]]);
     }
 
-    #[test]
-    fn test_any_and_all() {
-        assert!(any([1u, 2u, 3u], is_three));
-        assert!(!any([0u, 1u, 2u], is_three));
-        assert!(any([1u, 2u, 3u, 4u, 5u], is_three));
-        assert!(!any([1u, 2u, 4u, 5u, 6u], is_three));
-
-        assert!(all([3u, 3u, 3u], is_three));
-        assert!(!all([3u, 3u, 2u], is_three));
-        assert!(all([3u, 3u, 3u, 3u, 3u], is_three));
-        assert!(!all([3u, 3u, 0u, 1u, 2u], is_three));
-    }
-
-    #[test]
-    fn test_any2_and_all2() {
-
-        assert!(any2([2u, 4u, 6u], [2u, 4u, 6u], is_equal));
-        assert!(any2([1u, 2u, 3u], [4u, 5u, 3u], is_equal));
-        assert!(!any2([1u, 2u, 3u], [4u, 5u, 6u], is_equal));
-        assert!(any2([2u, 4u, 6u], [2u, 4u], is_equal));
-
-        assert!(all2([2u, 4u, 6u], [2u, 4u, 6u], is_equal));
-        assert!(!all2([1u, 2u, 3u], [4u, 5u, 3u], is_equal));
-        assert!(!all2([1u, 2u, 3u], [4u, 5u, 6u], is_equal));
-        assert!(!all2([2u, 4u, 6u], [2u, 4u], is_equal));
-    }
-
     #[test]
     fn test_zip_unzip() {
         let v1 = ~[1, 2, 3];
@@ -4361,81 +4266,6 @@ fn test_foldr_fail() {
         };
     }
 
-    #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    fn test_any_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        let mut i = 0;
-        do any(v) |_elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 0;
-            false
-        };
-    }
-
-    #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    fn test_any2_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        let mut i = 0;
-        do any(v) |_elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 0;
-            false
-        };
-    }
-
-    #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    fn test_all_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        let mut i = 0;
-        do all(v) |_elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 0;
-            true
-        };
-    }
-
-    #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    fn test_alli_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        let mut i = 0;
-        do alli(v) |_i, _elt| {
-            if i == 2 {
-                fail!()
-            }
-            i += 0;
-            true
-        };
-    }
-
-    #[test]
-    #[ignore(windows)]
-    #[should_fail]
-    fn test_all2_fail() {
-        let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)];
-        let mut i = 0;
-        do all2(v, v) |_elt1, _elt2| {
-            if i == 2 {
-                fail!()
-            }
-            i += 0;
-            true
-        };
-    }
-
     #[test]
     #[ignore(windows)]
     #[should_fail]
@@ -4617,7 +4447,7 @@ fn test_rev_iterator() {
     #[test]
     fn test_mut_rev_iterator() {
         use iterator::*;
-        let mut xs = [1, 2, 3, 4, 5];
+        let mut xs = [1u, 2, 3, 4, 5];
         for xs.mut_rev_iter().enumerate().advance |(i,x)| {
             *x += i;
         }
index 38cc31273430222cbb50f276bc8fc935a3d51fff..684d2ac5009b521196649239258348db48a07e2a 100644 (file)
@@ -21,6 +21,7 @@
 use extra::time;
 use extra::deque::Deque;
 use extra::par;
+use std::iterator::IteratorUtil;
 use std::hashmap::HashSet;
 use std::int::abs;
 use std::io;
@@ -111,7 +112,7 @@ fn gen_search_keys(graph: &[~[node_id]], n: uint) -> ~[node_id] {
     while keys.len() < n {
         let k = r.gen_uint_range(0u, graph.len());
 
-        if graph[k].len() > 0u && vec::any(graph[k], |i| {
+        if graph[k].len() > 0u && graph[k].iter().any(|i| {
             *i != k as node_id
         }) {
             keys.insert(k as node_id);
@@ -187,7 +188,7 @@ fn is_gray(c: &color) -> bool {
     }
 
     let mut i = 0;
-    while vec::any(colors, is_gray) {
+    while colors.iter().any(is_gray) {
         // Do the BFS.
         info!("PBFS iteration %?", i);
         i += 1;
index 906a3629f3a0a6ffb8d20b6a201eb8c589a4d574..ae6e04b30180748fb8b9653d61d6d89798ffd962 100644 (file)
@@ -8,6 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use std::iterator::IteratorUtil;
 use std::vec;
 
 // Check usage and precedence of block arguments in expressions:
@@ -20,28 +21,28 @@ pub fn main() {
     }
 
     // Usable at all:
-    let mut any_negative = do vec::any(v) |e| { e.is_negative() };
+    let mut any_negative = do v.iter().any |e| { e.is_negative() };
     assert!(any_negative);
 
     // Higher precedence than assignments:
-    any_negative = do vec::any(v) |e| { e.is_negative() };
+    any_negative = do v.iter().any |e| { e.is_negative() };
     assert!(any_negative);
 
     // Higher precedence than unary operations:
     let abs_v = do vec::map(v) |e| { e.abs() };
-    assert!(do vec::all(abs_v) |e| { e.is_positive() });
-    assert!(!do vec::any(abs_v) |e| { e.is_negative() });
+    assert!(do abs_v.iter().all |e| { e.is_positive() });
+    assert!(!do abs_v.iter().any |e| { e.is_negative() });
 
     // Usable in funny statement-like forms:
-    if !do vec::any(v) |e| { e.is_positive() } {
+    if !do v.iter().any |e| { e.is_positive() } {
         assert!(false);
     }
-    match do vec::all(v) |e| { e.is_negative() } {
+    match do v.iter().all |e| { e.is_negative() } {
         true => { fail!("incorrect answer."); }
         false => { }
     }
     match 3 {
-      _ if do vec::any(v) |e| { e.is_negative() } => {
+      _ if do v.iter().any |e| { e.is_negative() } => {
       }
       _ => {
         fail!("wrong answer.");
@@ -58,7 +59,7 @@ pub fn main() {
 
     // In the tail of a block
     let w =
-        if true { do vec::any(abs_v) |e| { e.is_positive() } }
+        if true { do abs_v.iter().any |e| { e.is_positive() } }
       else { false };
     assert!(w);
 }
index 80e6293bf50af6594e2111b1fca67529e950e0c1..4346d242c06bfd746d641ccde5d11371bfa82207 100644 (file)
@@ -10,6 +10,7 @@
 
 // xfail-fast
 
+use std::iterator::IteratorUtil;
 use std::cmp::Eq;
 use std::vec;
 
@@ -54,7 +55,8 @@ fn ret_deep() -> ~str {
 
 pub fn main() {
     let mut last = 0;
-    for vec::all(~[1, 2, 3, 4, 5, 6, 7]) |e| {
+    let v = ~[1, 2, 3, 4, 5, 6, 7];
+    for v.iter().all |e| {
         last = *e;
         if *e == 5 { break; }
         if *e % 2 == 1 { loop; }
index d8b12437dfa327a2ebaf7b311c03794809bb758c..cbfaa87b69952aa7731adc99cc1aaa78557376d0 100644 (file)
@@ -13,7 +13,7 @@
 
 extern mod extra;
 
-use std::vec;
+use std::iterator::IteratorUtil;
 
 #[test]
 #[ignore(cfg(ignorecfg))]
@@ -30,11 +30,9 @@ fn checktests() {
     // Pull the tests out of the secreturn test module
     let tests = __test::tests;
 
-    assert!(vec::any(
-        tests,
-        |t| t.desc.name.to_str() == ~"shouldignore" && t.desc.ignore));
+    assert!(
+        tests.iter().any(|t| t.desc.name.to_str() == ~"shouldignore" && t.desc.ignore));
 
-    assert!(vec::any(
-        tests,
-        |t| t.desc.name.to_str() == ~"shouldnotignore" && !t.desc.ignore));
+    assert!(
+        tests.iter().any(|t| t.desc.name.to_str() == ~"shouldnotignore" && !t.desc.ignore));
 }