Skip to content

Commit 5b2451c

Browse files
committed
Address _vec.map allocation FIXME. Add test.
1 parent 5796ebb commit 5b2451c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/lib/_vec.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,10 @@ fn grow[T](&mutable vec[T] v, int n, &T initval) {
7676
}
7777
}
7878

79-
fn map[T,U](&op[T,U] f, &vec[T] v) -> vec[U] {
80-
// FIXME: should be
81-
// let vec[U] u = alloc[U](len[T](v));
82-
// but this does not work presently.
83-
let vec[U] u = vec();
79+
fn map[T, U](&op[T,U] f, &vec[T] v) -> vec[U] {
80+
let vec[U] u = alloc[U](len[T](v));
8481
for (T ve in v) {
8582
u += vec(f(ve));
8683
}
8784
ret u;
8885
}
89-

src/test/run-pass/vec-lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ fn test_slice() {
3030
check (v2.(1) == 4);
3131
}
3232

33+
fn test_map() {
34+
fn square(&int x) -> int { ret x * x; }
35+
let std.util.operator[int, int] op = square;
36+
let vec[int] v = vec(1, 2, 3, 4, 5);
37+
let vec[int] s = std._vec.map[int, int](op, v);
38+
let int i = 0;
39+
while (i < 5) {
40+
check (v.(i) == s.(i));
41+
i += 1;
42+
}
43+
}
44+
3345
fn main() {
3446
test_init_elt();
3547
//XFAIL: test_init_fn(); // Segfaults.

0 commit comments

Comments
 (0)