diff --git a/src/libcore/iterator.rs b/src/libcore/iterator.rs index 40c9637f692..3811d28b030 100644 --- a/src/libcore/iterator.rs +++ b/src/libcore/iterator.rs @@ -45,6 +45,7 @@ fn scan<'r, St, B>(self, initial_state: St, f: &'r fn(&mut St, A) -> Option) fn advance(&mut self, f: &fn(A) -> bool); #[cfg(not(stage0))] fn advance(&mut self, f: &fn(A) -> bool) -> bool; + fn to_vec(self) -> ~[A]; } /// Iterator adaptors provided for every `Iterator` implementation. The adaptor objects are also @@ -131,6 +132,14 @@ fn advance(&mut self, f: &fn(A) -> bool) -> bool { } } } + + #[inline(always)] + fn to_vec(self) -> ~[A] { + let mut v = ~[]; + let mut it = self; + for it.advance() |x| { v.push(x); } + return v; + } } pub struct ChainIterator {