Skip to content

Commit 69dc448

Browse files
committed
---
yaml --- r: 56431 b: refs/heads/auto c: 92bf9b6 h: refs/heads/master i: 56429: e026cce 56427: ccb91ed 56423: 9619c6a 56415: 6072b3f v: v3
1 parent 22608de commit 69dc448

File tree

16 files changed

+358
-1159
lines changed

16 files changed

+358
-1159
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 225ac216157cf530332cef1c926875e2023e48e6
17+
refs/heads/auto: 92bf9b68da05504e925e2b66ceb9f3e5f1a5b0ee
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

branches/auto/src/libcore/core.rc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ pub use kinds::{Const, Copy, Owned, Durable};
7777
pub use ops::{Drop};
7878
#[cfg(stage0)]
7979
pub use ops::{Add, Sub, Mul, Div, Modulo, Neg, Not};
80-
#[cfg(not(stage0))]
80+
#[cfg(stage1)]
81+
#[cfg(stage2)]
82+
#[cfg(stage3)]
8183
pub use ops::{Add, Sub, Mul, Quot, Rem, Neg, Not};
8284
pub use ops::{BitAnd, BitOr, BitXor};
8385
pub use ops::{Shl, Shr, Index};
@@ -103,9 +105,7 @@ pub use iter::{BaseIter, ExtendedIter, EqIter, CopyableIter};
103105
pub use iter::{CopyableOrderedIter, CopyableNonstrictIter, Times};
104106
pub use iter::{ExtendedMutableIter};
105107

106-
pub use num::{Num, NumCast};
107-
pub use num::{Signed, Unsigned, Integer};
108-
pub use num::{Round, Fractional, Real, RealExt};
108+
pub use num::{Num, Signed, Unsigned, Natural, NumCast};
109109
pub use ptr::Ptr;
110110
pub use to_str::ToStr;
111111
pub use clone::Clone;

branches/auto/src/libcore/iterator.rs

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,19 @@ impl<A, T: Iterator<A>> Iterator<A> for TakeIterator<T> {
312312
}
313313
}
314314

315+
pub struct ScanIterator<'self, A, B, T, St> {
316+
priv iter: T,
317+
priv f: &'self fn(&mut St, A) -> Option<B>,
318+
state: St
319+
}
320+
321+
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
322+
#[inline]
323+
fn next(&mut self) -> Option<B> {
324+
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
325+
}
326+
}
327+
315328
pub struct UnfoldrIterator<'self, A, St> {
316329
priv f: &'self fn(&mut St) -> Option<A>,
317330
state: St
@@ -335,16 +348,25 @@ impl<'self, A, St> Iterator<A> for UnfoldrIterator<'self, A, St> {
335348
}
336349
}
337350

338-
pub struct ScanIterator<'self, A, B, T, St> {
339-
priv iter: T,
340-
priv f: &'self fn(&mut St, A) -> Option<B>,
341-
state: St
351+
/// An infinite iterator starting at `start` and advancing by `step` with each iteration
352+
pub struct Counter<A> {
353+
state: A,
354+
step: A
342355
}
343356

344-
impl<'self, A, B, T: Iterator<A>, St> Iterator<B> for ScanIterator<'self, A, B, T, St> {
345-
#[inline]
346-
fn next(&mut self) -> Option<B> {
347-
self.iter.next().chain(|a| (self.f)(&mut self.state, a))
357+
pub impl<A> Counter<A> {
358+
#[inline(always)]
359+
fn new(start: A, step: A) -> Counter<A> {
360+
Counter{state: start, step: step}
361+
}
362+
}
363+
364+
impl<A: Add<A, A> + Clone> Iterator<A> for Counter<A> {
365+
#[inline(always)]
366+
fn next(&mut self) -> Option<A> {
367+
let result = self.state.clone();
368+
self.state = self.state.add(&self.step); // FIXME: #6050
369+
Some(result)
348370
}
349371
}
350372

@@ -353,6 +375,13 @@ mod tests {
353375
use super::*;
354376
use prelude::*;
355377

378+
#[test]
379+
fn test_counter_to_vec() {
380+
let mut it = Counter::new(0, 5).take(10);
381+
let xs = iter::iter_to_vec(|f| it.advance(f));
382+
assert_eq!(xs, ~[0, 5, 10, 15, 20, 25, 30, 35, 40, 45]);
383+
}
384+
356385
#[test]
357386
fn test_iterator_chain() {
358387
let xs = [0u, 1, 2, 3, 4, 5];

0 commit comments

Comments
 (0)