diff options
| author | bors <bors@rust-lang.org> | 2013-05-10 17:56:02 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-05-10 17:56:02 -0700 |
| commit | 3e0400fb86170baff30282edcdccff73e243fd6e (patch) | |
| tree | ec7cc5de5ce7c80845c77fdcbb670cd54c120783 /src/libstd/list.rs | |
| parent | d546493096f35e68cbcd9b5d3d7654e7a9345744 (diff) | |
| parent | 606bd75586419948f109de313ab37e31397ca7a3 (diff) | |
| download | rust-3e0400fb86170baff30282edcdccff73e243fd6e.tar.gz rust-3e0400fb86170baff30282edcdccff73e243fd6e.zip | |
auto merge of #6223 : alexcrichton/rust/issue-6183, r=pcwalton
Closes #6183. The first commit changes the compiler's method of treating a `for` loop, and all the remaining commits are just dealing with the fallout. The biggest fallout was the `IterBytes` trait, although it's really a whole lot nicer now because all of the `iter_bytes_XX` methods are just and-ed together. Sadly there was a huge amount of stuff that's `cfg(stage0)` gated, but whoever lands the next snapshot is going to have a lot of fun deleting all this code!
Diffstat (limited to 'src/libstd/list.rs')
| -rw-r--r-- | src/libstd/list.rs | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 8d15508b26e..13ef377fabe 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -140,6 +140,7 @@ pub fn iter<T>(l: @List<T>, f: &fn(&T)) { } /// Iterate over a list +#[cfg(stage0)] pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) { let mut cur = l; loop { @@ -152,9 +153,24 @@ pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) { } } } +/// Iterate over a list +#[cfg(not(stage0))] +pub fn each<T>(l: @List<T>, f: &fn(&T) -> bool) -> bool { + let mut cur = l; + loop { + cur = match *cur { + Cons(ref hd, tl) => { + if !f(hd) { return false; } + tl + } + Nil => { return true; } + } + } +} impl<T> MutList<T> { /// Iterate over a mutable list + #[cfg(stage0)] pub fn each(@mut self, f: &fn(&mut T) -> bool) { let mut cur = self; loop { @@ -170,6 +186,24 @@ impl<T> MutList<T> { } } } + /// Iterate over a mutable list + #[cfg(not(stage0))] + pub fn each(@mut self, f: &fn(&mut T) -> bool) -> bool { + let mut cur = self; + loop { + let borrowed = &mut *cur; + cur = match *borrowed { + MutCons(ref mut hd, tl) => { + if !f(hd) { + return false; + } + tl + } + MutNil => break + } + } + return true; + } } #[cfg(test)] |
