@@ -19,6 +19,41 @@ native "c-stack-cdecl" mod rustrt {
19
19
count : uint ) -> [ T ] ;
20
20
}
21
21
22
+ /*
23
+ Type: init_op
24
+
25
+ A function used to initialize the elements of a vector.
26
+ */
27
+ type init_op < T > = block ( uint ) -> T ;
28
+
29
+
30
+ /*
31
+ Predicate: is_empty
32
+
33
+ Returns true if a vector contains no elements.
34
+ */
35
+ pure fn is_empty < T > ( v : [ mutable? T ] ) -> bool {
36
+ // FIXME: This would be easier if we could just call len
37
+ for t: T in v { ret false ; }
38
+ ret true;
39
+ }
40
+
41
+ /*
42
+ Predicate: is_not_empty
43
+
44
+ Returns true if a vector contains some elements.
45
+ */
46
+ pure fn is_not_empty < T > ( v : [ mutable? T ] ) -> bool { ret ! is_empty( v) ; }
47
+
48
+ /*
49
+ Predicate: same_length
50
+
51
+ Returns true if two vectors have the same length
52
+ */
53
+ pure fn same_length < T , U > ( xs : [ T ] , ys : [ U ] ) -> bool {
54
+ vec:: len ( xs) == vec:: len ( ys)
55
+ }
56
+
22
57
/*
23
58
Function: reserve
24
59
@@ -43,13 +78,6 @@ Returns the length of a vector
43
78
*/
44
79
pure fn len < T > ( v : [ mutable? T ] ) -> uint { unchecked { rusti : : vec_len ( v) } }
45
80
46
- /*
47
- Type: init_op
48
-
49
- A function used to initialize the elements of a vector.
50
- */
51
- type init_op < T > = block ( uint ) -> T ;
52
-
53
81
/*
54
82
Function: init_fn
55
83
@@ -141,24 +169,6 @@ fn from_mut<T>(v: [mutable T]) -> [T] {
141
169
ret vres;
142
170
}
143
171
144
- /*
145
- Predicate: is_empty
146
-
147
- Returns true if a vector contains no elements.
148
- */
149
- pure fn is_empty < T > ( v : [ mutable? T ] ) -> bool {
150
- // FIXME: This would be easier if we could just call len
151
- for t: T in v { ret false ; }
152
- ret true;
153
- }
154
-
155
- /*
156
- Predicate: is_not_empty
157
-
158
- Returns true if a vector contains some elements.
159
- */
160
- pure fn is_not_empty < T > ( v : [ mutable? T ] ) -> bool { ret ! is_empty( v) ; }
161
-
162
172
// Accessors
163
173
164
174
/*
@@ -519,15 +529,6 @@ fn position_pred<T>(f: block(T) -> bool, v: [T]) -> option::t<uint> {
519
529
ret none;
520
530
}
521
531
522
- /*
523
- Predicate: same_length
524
-
525
- Returns true if two vectors have the same length
526
- */
527
- pure fn same_length < T , U > ( xs : [ T ] , ys : [ U ] ) -> bool {
528
- vec:: len ( xs) == vec:: len ( ys)
529
- }
530
-
531
532
// FIXME: if issue #586 gets implemented, could have a postcondition
532
533
// saying the two result lists have the same length -- or, could
533
534
// return a nominal record with a constraint saying that, instead of
0 commit comments