blob: 11dd2ffd2c573002363f37eef07de632023307d2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
use std;
fn test_init_elt() {
let vec[uint] v = std._vec.init_elt[uint](uint(5), uint(3));
check (std._vec.len[uint](v) == uint(3));
check (v.(0) == uint(5));
check (v.(1) == uint(5));
check (v.(2) == uint(5));
}
fn id(uint x) -> uint {
ret x;
}
fn test_init_fn() {
let fn(uint)->uint op = id;
let vec[uint] v = std._vec.init_fn[uint](op, uint(5));
// FIXME #108: Can't call templated function twice in the same
// program, at the moment.
//check (std._vec.len[uint](v) == uint(5));
check (v.(0) == uint(0));
check (v.(1) == uint(1));
check (v.(2) == uint(2));
check (v.(3) == uint(3));
check (v.(4) == uint(4));
}
fn test_slice() {
let vec[int] v = vec(1,2,3,4,5);
auto v2 = std._vec.slice[int](v, 2, 4);
// FIXME #108: Can't call templated function twice in the same
// program, at the moment.
//check (std._vec.len[int](v2) == uint(2));
check (v2.(0) == 3);
check (v2.(1) == 4);
}
fn main() {
test_init_elt();
//XFAIL: test_init_fn(); // Segfaults.
test_slice();
}
|