std: Demode more of list and treemap

This commit is contained in:
Brian Anderson 2012-09-26 18:12:07 -07:00
parent 5424f21d5d
commit 0ec267b276
4 changed files with 8 additions and 8 deletions

View file

@ -63,7 +63,7 @@ struct Arena {
unsafe {
destroy_chunk(&self.head);
for list::each(self.chunks) |chunk| {
if !chunk.is_pod { destroy_chunk(&chunk); }
if !chunk.is_pod { destroy_chunk(chunk); }
}
}
}

View file

@ -59,7 +59,7 @@ fn find<T: Copy>(ls: @List<T>, f: fn((&T)) -> bool) -> Option<T> {
/// Returns true if a list contains an element with the given value
fn has<T: Copy Eq>(ls: @List<T>, +elt: T) -> bool {
for each(ls) |e| {
if e == elt { return true; }
if *e == elt { return true; }
}
return false;
}
@ -135,11 +135,11 @@ fn iter<T>(l: @List<T>, f: fn((&T))) {
}
/// Iterate over a list
fn each<T>(l: @List<T>, f: fn(T) -> bool) {
fn each<T>(l: @List<T>, f: fn((&T)) -> bool) {
let mut cur = l;
loop {
cur = match *cur {
Cons(hd, tl) => {
Cons(ref hd, tl) => {
if !f(hd) { return; }
tl
}

View file

@ -73,13 +73,13 @@ fn find<K: Copy Eq Ord, V: Copy>(m: &const TreeEdge<K, V>, +k: K)
}
/// Visit all pairs in the map in order.
fn traverse<K, V: Copy>(m: &const TreeEdge<K, V>, f: fn(K, V)) {
fn traverse<K, V: Copy>(m: &const TreeEdge<K, V>, f: fn((&K), (&V))) {
match copy *m {
None => (),
Some(node) => {
traverse(&const node.left, f);
// copy of value is req'd as f() requires an immutable ptr
f(node.key, copy node.value);
f(&node.key, &copy node.value);
traverse(&const node.right, f);
}
}
@ -130,7 +130,7 @@ mod tests {
fn t(n: @mut int, +k: int, +_v: ()) {
assert (*n == k); *n += 1;
}
traverse(m, |x,y| t(n, x, y));
traverse(m, |x,y| t(n, *x, *y));
}
#[test]

View file

@ -181,7 +181,7 @@ impl isr_alist: get_and_find_region {
fn find(br: ty::bound_region) -> Option<ty::region> {
for list::each(self) |isr| {
let (isr_br, isr_r) = isr;
let (isr_br, isr_r) = *isr;
if isr_br == br { return Some(isr_r); }
}
return None;