diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/at_vec.rs | 9 | ||||
| -rw-r--r-- | src/libstd/hashmap.rs | 13 | ||||
| -rw-r--r-- | src/libstd/iterator.rs | 36 | ||||
| -rw-r--r-- | src/libstd/num/int_macros.rs | 15 | ||||
| -rw-r--r-- | src/libstd/num/uint_macros.rs | 15 | ||||
| -rw-r--r-- | src/libstd/os.rs | 7 | ||||
| -rw-r--r-- | src/libstd/prelude.rs | 3 | ||||
| -rw-r--r-- | src/libstd/rand.rs | 3 | ||||
| -rw-r--r-- | src/libstd/rt/args.rs | 7 | ||||
| -rw-r--r-- | src/libstd/rt/io/net/tcp.rs | 10 | ||||
| -rw-r--r-- | src/libstd/rt/sched.rs | 7 | ||||
| -rw-r--r-- | src/libstd/rt/select.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/test.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/tube.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/uv/uvio.rs | 12 | ||||
| -rw-r--r-- | src/libstd/run.rs | 5 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 6 | ||||
| -rw-r--r-- | src/libstd/unstable/sync.rs | 6 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 8 |
19 files changed, 84 insertions, 90 deletions
diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 22cbcb0d6d4..ab1dd3d45f1 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -12,10 +12,9 @@ use clone::Clone; use container::Container; -use iterator::Iterator; +use iterator::{Iterator, range}; use option::{Option, Some, None}; use sys; -use uint; use unstable::raw::Repr; use vec::{ImmutableVector, OwnedVector}; @@ -95,7 +94,7 @@ pub fn append<T:Clone>(lhs: @[T], rhs: &[T]) -> @[T] { foreach x in lhs.iter() { push((*x).clone()); } - for uint::range(0, rhs.len()) |i| { + foreach i in range(0u, rhs.len()) { push(rhs[i].clone()); } } @@ -323,14 +322,14 @@ pub mod raw { #[cfg(test)] mod test { use super::*; - use uint; + use prelude::*; #[test] fn test() { // Some code that could use that, then: fn seq_range(lo: uint, hi: uint) -> @[uint] { do build |push| { - for uint::range(lo, hi) |i| { + foreach i in range(lo, hi) { push(i); } } diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index ca61f3e5ad8..e7d51106c58 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -19,7 +19,7 @@ use container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; use clone::Clone; use cmp::{Eq, Equiv}; use hash::Hash; -use iterator::{Iterator, IteratorUtil, FromIterator, Extendable, Chain}; +use iterator::{Iterator, IteratorUtil, FromIterator, Extendable, Chain, range}; use num; use option::{None, Option, Some}; use rand::RngUtil; @@ -284,7 +284,7 @@ impl<K:Hash + Eq,V> Container for HashMap<K, V> { impl<K:Hash + Eq,V> Mutable for HashMap<K, V> { /// Clear the map, removing all key-value pairs. fn clear(&mut self) { - for uint::range(0, self.buckets.len()) |idx| { + foreach idx in range(0u, self.buckets.len()) { self.buckets[idx] = None; } self.size = 0; @@ -802,10 +802,8 @@ pub type SetAlgebraIter<'self, T> = #[cfg(test)] mod test_map { - use container::{Container, Map}; - use option::{None, Some}; + use prelude::*; use super::*; - use uint; #[test] fn test_create_capacity_zero() { @@ -930,7 +928,7 @@ mod test_map { #[test] fn test_iterate() { let mut m = linear_map_with_capacity(4); - for uint::range(0, 32) |i| { + foreach i in range(0u, 32) { assert!(m.insert(i, i*2)); } let mut observed = 0; @@ -1023,7 +1021,6 @@ mod test_set { use prelude::*; use container::Container; use vec::ImmutableEqVector; - use uint; #[test] fn test_disjoint() { @@ -1079,7 +1076,7 @@ mod test_set { #[test] fn test_iterate() { let mut a = HashSet::new(); - for uint::range(0, 32) |i| { + foreach i in range(0u, 32) { assert!(a.insert(i)); } let mut observed = 0; diff --git a/src/libstd/iterator.rs b/src/libstd/iterator.rs index 013901d57f8..3b829841484 100644 --- a/src/libstd/iterator.rs +++ b/src/libstd/iterator.rs @@ -47,6 +47,7 @@ pub trait Iterator<A> { /// Return a lower bound and upper bound on the remaining length of the iterator. /// /// The common use case for the estimate is pre-allocating space to store the results. + #[inline] fn size_hint(&self) -> (uint, Option<uint>) { (0, None) } } @@ -1513,11 +1514,38 @@ impl<A> Counter<A> { } } +/// A range of numbers from [0, N) +#[deriving(Clone, DeepClone)] +pub struct Range<A> { + priv state: A, + priv stop: A, + priv one: A +} + +/// Return an iterator over the range [start, stop) +#[inline] +pub fn range<A: Add<A, A> + Ord + Clone + One>(start: A, stop: A) -> Range<A> { + Range{state: start, stop: stop, one: One::one()} +} + +impl<A: Add<A, A> + Ord + Clone + One> Iterator<A> for Range<A> { + #[inline] + fn next(&mut self) -> Option<A> { + if self.state < self.stop { + let result = self.state.clone(); + self.state = self.state + self.one; + Some(result) + } else { + None + } + } +} + impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> { #[inline] fn next(&mut self) -> Option<A> { let result = self.state.clone(); - self.state = self.state.add(&self.step); // FIXME: #6050 + self.state = self.state + self.step; Some(result) } @@ -1703,13 +1731,13 @@ mod tests { #[test] fn test_cycle() { let cycle_len = 3; - let it = Counter::new(0u,1).take_(cycle_len).cycle(); + let it = Counter::new(0u, 1).take_(cycle_len).cycle(); assert_eq!(it.size_hint(), (uint::max_value, None)); foreach (i, x) in it.take_(100).enumerate() { assert_eq!(i % cycle_len, x); } - let mut it = Counter::new(0u,1).take_(0).cycle(); + let mut it = Counter::new(0u, 1).take_(0).cycle(); assert_eq!(it.size_hint(), (0, Some(0))); assert_eq!(it.next(), None); } @@ -1717,7 +1745,7 @@ mod tests { #[test] fn test_iterator_nth() { let v = &[0, 1, 2, 3, 4]; - for uint::range(0, v.len()) |i| { + foreach i in range(0u, v.len()) { assert_eq!(v.iter().nth(i).unwrap(), &v[i]); } } diff --git a/src/libstd/num/int_macros.rs b/src/libstd/num/int_macros.rs index cef32b5c7e4..9aa79090425 100644 --- a/src/libstd/num/int_macros.rs +++ b/src/libstd/num/int_macros.rs @@ -126,12 +126,6 @@ pub fn range_step_inclusive(start: $T, last: $T, step: $T, it: &fn($T) -> bool) #[inline] -/// Iterate over the range [`lo`..`hi`) -pub fn range(lo: $T, hi: $T, it: &fn($T) -> bool) -> bool { - range_step(lo, hi, 1 as $T, it) -} - -#[inline] /// Iterate over the range (`hi`..`lo`] pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool { if hi == min_value { return true; } @@ -895,9 +889,6 @@ mod tests { fn test_ranges() { let mut l = ~[]; - for range(0,3) |i| { - l.push(i); - } for range_rev(14,11) |i| { l.push(i); } @@ -919,8 +910,7 @@ mod tests { for range_step(min_value + 3, min_value, -2) |i| { l.push(i); } - assert_eq!(l, ~[0,1,2, - 13,12,11, + assert_eq!(l, ~[13,12,11, 20,22,24, 36,34,32, max_value-2, @@ -929,9 +919,6 @@ mod tests { min_value+3,min_value+1]); // None of the `fail`s should execute. - for range(10,0) |_i| { - fail!(~"unreachable"); - } for range_rev(0,10) |_i| { fail!(~"unreachable"); } diff --git a/src/libstd/num/uint_macros.rs b/src/libstd/num/uint_macros.rs index acf7ea683fb..aa01b871b9d 100644 --- a/src/libstd/num/uint_macros.rs +++ b/src/libstd/num/uint_macros.rs @@ -126,12 +126,6 @@ pub fn range_step_inclusive(start: $T, last: $T, step: $T_SIGNED, it: &fn($T) -> } #[inline] -/// Iterate over the range [`lo`..`hi`) -pub fn range(lo: $T, hi: $T, it: &fn($T) -> bool) -> bool { - range_step(lo, hi, 1 as $T_SIGNED, it) -} - -#[inline] /// Iterate over the range (`hi`..`lo`] pub fn range_rev(hi: $T, lo: $T, it: &fn($T) -> bool) -> bool { if hi == min_value { return true; } @@ -660,9 +654,6 @@ mod tests { pub fn test_ranges() { let mut l = ~[]; - for range(0,3) |i| { - l.push(i); - } for range_rev(14,11) |i| { l.push(i); } @@ -685,8 +676,7 @@ mod tests { l.push(i); } - assert_eq!(l, ~[0,1,2, - 13,12,11, + assert_eq!(l, ~[13,12,11, 20,22,24, 36,34,32, max_value-2, @@ -695,9 +685,6 @@ mod tests { min_value+3,min_value+1]); // None of the `fail`s should execute. - for range(0,0) |_i| { - fail!("unreachable"); - } for range_rev(0,0) |_i| { fail!("unreachable"); } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 1bfae8c40e1..8a1964783ae 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -32,7 +32,7 @@ use cast; use clone::Clone; use container::Container; use io; -use iterator::IteratorUtil; +use iterator::{IteratorUtil, range}; use libc; use libc::{c_char, c_void, c_int, size_t}; use libc::FILE; @@ -43,7 +43,6 @@ use prelude::*; use ptr; use str; use to_str; -use uint; use unstable::finally::Finally; use vec; @@ -1114,7 +1113,7 @@ pub fn set_exit_status(code: int) { unsafe fn load_argc_and_argv(argc: c_int, argv: **c_char) -> ~[~str] { let mut args = ~[]; - for uint::range(0, argc as uint) |i| { + foreach i in range(0u, argc as uint) { args.push(str::raw::from_c_str(*argv.offset(i as int))); } args @@ -1163,7 +1162,7 @@ pub fn real_args() -> ~[~str] { let szArgList = unsafe { CommandLineToArgvW(lpCmdLine, lpArgCount) }; let mut args = ~[]; - for uint::range(0, nArgs as uint) |i| { + foreach i in range(0u, nArgs as uint) { unsafe { // Determine the length of this argument. let ptr = *szArgList.offset(i as int); diff --git a/src/libstd/prelude.rs b/src/libstd/prelude.rs index 0d9446bcfca..517bc4a441a 100644 --- a/src/libstd/prelude.rs +++ b/src/libstd/prelude.rs @@ -40,6 +40,7 @@ pub use result::{Result, Ok, Err}; // Reexported functions pub use io::{print, println}; +pub use iterator::range; // Reexported types and traits pub use clone::{Clone, DeepClone}; @@ -49,7 +50,7 @@ pub use container::{Container, Mutable, Map, MutableMap, Set, MutableSet}; pub use hash::Hash; pub use iter::Times; pub use iterator::{Iterator, IteratorUtil, DoubleEndedIterator, DoubleEndedIteratorUtil}; -pub use iterator::OrdIterator; +pub use iterator::{ClonableIterator, OrdIterator}; pub use num::{Num, NumCast}; pub use num::{Orderable, Signed, Unsigned, Round}; pub use num::{Algebraic, Trigonometric, Exponential, Hyperbolic}; diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 9134d2da257..075e208ab82 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -48,6 +48,7 @@ use clone::Clone; use cmp; use container::Container; use int; +use iterator::{Iterator, range}; use local_data; use num; use prelude::*; @@ -582,7 +583,7 @@ impl<R: Rng> RngUtil for R { fn weighted_vec<T:Clone>(&mut self, v: &[Weighted<T>]) -> ~[T] { let mut r = ~[]; foreach item in v.iter() { - for uint::range(0u, item.weight) |_i| { + foreach _ in range(0u, item.weight) { r.push(item.item.clone()); } } diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index cd950471286..e701cb64fb6 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -53,11 +53,10 @@ pub fn clone() -> Option<~[~str]> { #[cfg(target_os = "android")] #[cfg(target_os = "freebsd")] mod imp { - use libc; use option::{Option, Some, None}; + use iterator::{Iterator, range}; use str; - use uint; use unstable::finally::Finally; use util; @@ -113,10 +112,10 @@ mod imp { // Copied from `os`. unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] { let mut args = ~[]; - for uint::range(0, argc as uint) |i| { + foreach i in range(0u, argc as uint) { args.push(str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int))); } - return args; + args } extern { diff --git a/src/libstd/rt/io/net/tcp.rs b/src/libstd/rt/io/net/tcp.rs index 2daa64e8085..764ef283eb8 100644 --- a/src/libstd/rt/io/net/tcp.rs +++ b/src/libstd/rt/io/net/tcp.rs @@ -143,11 +143,11 @@ impl Listener<TcpStream> for TcpListener { #[cfg(test)] mod test { use super::*; - use int; use cell::Cell; use rt::test::*; use rt::io::net::ip::Ipv4; use rt::io::*; + use prelude::*; #[test] #[ignore] fn bind_error() { @@ -421,7 +421,7 @@ mod test { do spawntask { let mut listener = TcpListener::bind(addr); - for int::range(0, MAX) |i| { + foreach i in range(0, MAX) { let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection @@ -460,7 +460,7 @@ mod test { do spawntask { let mut listener = TcpListener::bind(addr); - for int::range(0, MAX) |i| { + foreach i in range(0, MAX) { let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection @@ -499,7 +499,7 @@ mod test { do spawntask { let mut listener = TcpListener::bind(addr); - for int::range(0, MAX) |_| { + foreach _ in range(0, MAX) { let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection @@ -537,7 +537,7 @@ mod test { do spawntask { let mut listener = TcpListener::bind(addr); - for int::range(0, MAX) |_| { + foreach _ in range(0, MAX) { let stream = Cell::new(listener.accept()); rtdebug!("accepted"); // Start another task to handle the connection diff --git a/src/libstd/rt/sched.rs b/src/libstd/rt/sched.rs index 4abe69a7d13..3f394283bce 100644 --- a/src/libstd/rt/sched.rs +++ b/src/libstd/rt/sched.rs @@ -723,13 +723,12 @@ impl ClosureConverter for UnsafeTaskReceiver { #[cfg(test)] mod test { + use prelude::*; use rt::test::*; use unstable::run_in_bare_thread; use borrow::to_uint; use rt::local::*; use rt::sched::{Scheduler}; - use uint; - use int; use cell::Cell; use rt::thread::Thread; use rt::task::{Task, Sched}; @@ -752,7 +751,7 @@ mod test { let mut task_run_count = 0; let task_run_count_ptr: *mut uint = &mut task_run_count; do run_in_newsched_task || { - for uint::range(0,total) |_| { + foreach _ in range(0u, total) { do spawntask || { unsafe { *task_run_count_ptr = *task_run_count_ptr + 1}; } @@ -951,7 +950,7 @@ mod test { #[test] fn test_stress_schedule_task_states() { let n = stress_factor() * 120; - for int::range(0,n as int) |_| { + foreach _ in range(0, n as int) { test_schedule_home_states(); } } diff --git a/src/libstd/rt/select.rs b/src/libstd/rt/select.rs index b19357fa221..a5adb25b526 100644 --- a/src/libstd/rt/select.rs +++ b/src/libstd/rt/select.rs @@ -111,6 +111,7 @@ mod test { use comm::GenericChan; use task; use cell::Cell; + use iterator::{Iterator, range}; #[test] #[ignore(cfg(windows))] #[should_fail] fn select_doesnt_get_trolled() { @@ -263,7 +264,6 @@ mod test { select_racing_senders_helper(false, ~[7,8,9]); fn select_racing_senders_helper(killable: bool, send_on_chans: ~[uint]) { - use uint; use rt::test::spawntask_random; do run_in_newsched_task { @@ -272,7 +272,7 @@ mod test { let send_on_chans = send_on_chans.clone(); do task::spawn { let mut ports = ~[]; - for uint::range(0, NUM_CHANS) |i| { + foreach i in range(0u, NUM_CHANS) { let (p,c) = oneshot(); ports.push(p); if send_on_chans.contains(&i) { diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 22eb42e2ee8..1ed0703de4d 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -14,7 +14,7 @@ use option::{Some, None}; use cell::Cell; use clone::Clone; use container::Container; -use iterator::Iterator; +use iterator::{Iterator, range}; use vec::{OwnedVector, MutableVector}; use super::io::net::ip::{IpAddr, Ipv4, Ipv6}; use rt::sched::Scheduler; @@ -90,7 +90,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { let mut handles = ~[]; let mut scheds = ~[]; - for uint::range(0, nthreads) |_| { + foreach _ in range(0u, nthreads) { let loop_ = ~UvEventLoop::new(); let mut sched = ~Scheduler::new(loop_, work_queue.clone(), diff --git a/src/libstd/rt/tube.rs b/src/libstd/rt/tube.rs index ae455a6ad04..c014d0abda2 100644 --- a/src/libstd/rt/tube.rs +++ b/src/libstd/rt/tube.rs @@ -88,13 +88,13 @@ impl<T> Clone for Tube<T> { #[cfg(test)] mod test { - use int; use cell::Cell; use rt::test::*; use rt::rtio::EventLoop; use rt::sched::Scheduler; use rt::local::Local; use super::*; + use prelude::*; #[test] fn simple_test() { @@ -166,7 +166,7 @@ mod test { sched.enqueue_blocked_task(task); } - for int::range(0, MAX) |i| { + foreach i in range(0, MAX) { let j = tube.recv(); assert!(j == i); } diff --git a/src/libstd/rt/uv/uvio.rs b/src/libstd/rt/uv/uvio.rs index 5be19752152..e15e3adb8c9 100644 --- a/src/libstd/rt/uv/uvio.rs +++ b/src/libstd/rt/uv/uvio.rs @@ -31,11 +31,11 @@ use str::StrSlice; use unstable::sync::Exclusive; #[cfg(test)] use container::Container; -#[cfg(test)] use uint; #[cfg(test)] use unstable::run_in_bare_thread; #[cfg(test)] use rt::test::{spawntask, next_test_ip4, run_in_newsched_task}; +#[cfg(test)] use iterator::{Iterator, range}; enum SocketNameKind { TcpPeer, @@ -843,7 +843,7 @@ fn test_simple_tcp_server_and_client() { let mut buf = [0, .. 2048]; let nread = stream.read(buf).unwrap(); assert_eq!(nread, 8); - for uint::range(0, nread) |i| { + foreach i in range(0u, nread) { rtdebug!("%u", buf[i] as uint); assert_eq!(buf[i], i as u8); } @@ -873,7 +873,7 @@ fn test_simple_udp_server_and_client() { let mut buf = [0, .. 2048]; let (nread,src) = server_socket.recvfrom(buf).unwrap(); assert_eq!(nread, 8); - for uint::range(0, nread) |i| { + foreach i in range(0u, nread) { rtdebug!("%u", buf[i] as uint); assert_eq!(buf[i], i as u8); } @@ -908,7 +908,7 @@ fn test_read_and_block() { while current < expected { let nread = stream.read(buf).unwrap(); - for uint::range(0, nread) |i| { + foreach i in range(0u, nread) { let val = buf[i] as uint; assert_eq!(val, current % 8); current += 1; @@ -973,7 +973,7 @@ fn test_read_read_read() { let nread = stream.read(buf).unwrap(); rtdebug!("read %u bytes", nread as uint); total_bytes_read += nread; - for uint::range(0, nread) |i| { + foreach i in range(0u, nread) { assert_eq!(buf[i], 1); } } @@ -1065,7 +1065,7 @@ fn test_udp_many_read() { let (nread, src) = res.unwrap(); assert_eq!(src, server_out_addr); total_bytes_recv += nread; - for uint::range(0, nread) |i| { + foreach i in range(0u, nread) { assert_eq!(buf[i], 1); } } diff --git a/src/libstd/run.rs b/src/libstd/run.rs index acdc97da58c..8af5a6dfac7 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -574,9 +574,6 @@ fn zeroed_process_information() -> libc::types::os::arch::extra::PROCESS_INFORMA // FIXME: this is only pub so it can be tested (see issue #4536) #[cfg(windows)] pub fn make_command_line(prog: &str, args: &[~str]) -> ~str { - - use uint; - let mut cmd = ~""; append_arg(&mut cmd, prog); foreach arg in args.iter() { @@ -590,7 +587,7 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str { if quote { cmd.push_char('"'); } - for uint::range(0, arg.len()) |i| { + foreach i in range(0u, arg.len()) { append_char_at(cmd, arg, i); } if quote { diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index f60093ce48c..97e2b3b3c34 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -261,7 +261,7 @@ impl<T> TrieNode<T> { impl<T> TrieNode<T> { fn each<'a>(&'a self, f: &fn(&uint, &'a T) -> bool) -> bool { - for uint::range(0, self.children.len()) |idx| { + foreach idx in range(0u, self.children.len()) { match self.children[idx] { Internal(ref x) => if !x.each(|i,t| f(i,t)) { return false }, External(k, ref v) => if !f(&k, v) { return false }, @@ -396,7 +396,7 @@ pub fn check_integrity<T>(trie: &TrieNode<T>) { #[cfg(test)] mod test_map { use super::*; - use option::{Some, None}; + use prelude::*; use uint; #[test] @@ -429,7 +429,7 @@ mod test_map { check_integrity(&trie.root); } - for uint::range(0, n) |x| { + foreach x in range(0u, n) { assert!(trie.contains_key(&x)); assert!(!trie.insert(x, x + 1)); check_integrity(&trie.root); diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index f5c82bad2b1..4b5c72e5a86 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -436,9 +436,9 @@ mod tests { use cell::Cell; use comm; use option::*; + use prelude::*; use super::{Exclusive, UnsafeAtomicRcBox, atomically}; use task; - use uint; use util; #[test] @@ -458,13 +458,13 @@ mod tests { let total = Exclusive::new(~0); - for uint::range(0, num_tasks) |_i| { + foreach _ in range(0u, num_tasks) { let total = total.clone(); let (port, chan) = comm::stream(); futures.push(port); do task::spawn || { - for uint::range(0, count) |_i| { + foreach _ in range(0u, count) { do total.with |count| { **count += 1; } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 6cff9ce84cf..ad5ded2002a 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -473,7 +473,7 @@ pub fn each_permutation<T:Clone>(values: &[T], fun: &fn(perm : &[T]) -> bool) -> indices.swap(k, l); indices.mut_slice(k+1, length).reverse(); // fixup permutation based on indices - for uint::range(k, length) |i| { + foreach i in range(k, length) { permutation[i] = values[indices[i]].clone(); } } @@ -1461,7 +1461,7 @@ impl<T> OwnedVector<T> for ~[T] { assert!(newlen <= oldlen); unsafe { // This loop is optimized out for non-drop types. - for uint::range(newlen, oldlen) |i| { + foreach i in range(newlen, oldlen) { ptr::read_and_zero_ptr(ptr::mut_offset(p, i as int)); } } @@ -1477,7 +1477,7 @@ impl<T> OwnedVector<T> for ~[T] { let len = self.len(); let mut deleted: uint = 0; - for uint::range(0, len) |i| { + foreach i in range(0u, len) { if !f(&self[i]) { deleted += 1; } else if deleted > 0 { @@ -1561,7 +1561,7 @@ impl<T:Clone> OwnedCopyableVector<T> for ~[T] { let new_len = self.len() + rhs.len(); self.reserve(new_len); - for uint::range(0u, rhs.len()) |i| { + foreach i in range(0u, rhs.len()) { self.push(unsafe { raw::get(rhs, i) }) } } |
