Skip to content

Commit 0f9eb15

Browse files
committed
---
yaml --- r: 57193 b: refs/heads/try c: 92bf9b6 h: refs/heads/master i: 57191: 45edb94 v: v3
1 parent 7f8168e commit 0f9eb15

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
@@ -2,7 +2,7 @@
22
refs/heads/master: c081ffbd1e845687202a975ea2e698b623e5722f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 79a2b2eafc3c766cecec8a5f76317693bae9ed17
5-
refs/heads/try: 225ac216157cf530332cef1c926875e2023e48e6
5+
refs/heads/try: 92bf9b68da05504e925e2b66ceb9f3e5f1a5b0ee
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/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/try/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)