aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib/_vec.rs8
-rw-r--r--src/test/run-pass/vec-lib.rs12
2 files changed, 14 insertions, 6 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs
index 13fbeb6a..43779015 100644
--- a/src/lib/_vec.rs
+++ b/src/lib/_vec.rs
@@ -76,14 +76,10 @@ fn grow[T](&mutable vec[T] v, int n, &T initval) {
}
}
-fn map[T,U](&op[T,U] f, &vec[T] v) -> vec[U] {
- // FIXME: should be
- // let vec[U] u = alloc[U](len[T](v));
- // but this does not work presently.
- let vec[U] u = vec();
+fn map[T, U](&op[T,U] f, &vec[T] v) -> vec[U] {
+ let vec[U] u = alloc[U](len[T](v));
for (T ve in v) {
u += vec(f(ve));
}
ret u;
}
-
diff --git a/src/test/run-pass/vec-lib.rs b/src/test/run-pass/vec-lib.rs
index 90a95ff9..ccd83d33 100644
--- a/src/test/run-pass/vec-lib.rs
+++ b/src/test/run-pass/vec-lib.rs
@@ -30,6 +30,18 @@ fn test_slice() {
check (v2.(1) == 4);
}
+fn test_map() {
+ fn square(&int x) -> int { ret x * x; }
+ let std.util.operator[int, int] op = square;
+ let vec[int] v = vec(1, 2, 3, 4, 5);
+ let vec[int] s = std._vec.map[int, int](op, v);
+ let int i = 0;
+ while (i < 5) {
+ check (v.(i) == s.(i));
+ i += 1;
+ }
+}
+
fn main() {
test_init_elt();
//XFAIL: test_init_fn(); // Segfaults.