File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,18 @@ fn init_elt_mut[T](&T t, uint n_elts) -> T[mutable] {
72
72
ret v;
73
73
}
74
74
75
+ // Predicates
76
+ pred is_empty[ T ] ( & T [ mutable?] v) -> bool {
77
+ // FIXME: This would be easier if we could just call len
78
+ for ( T t in v) {
79
+ ret false;
80
+ }
81
+ ret true;
82
+ }
83
+
84
+ pred is_not_empty[ T ] ( & T [ mutable?] v) -> bool {
85
+ ret !is_empty( v) ;
86
+ }
75
87
76
88
// Accessors
77
89
@@ -247,3 +259,11 @@ mod unsafe {
247
259
}
248
260
}
249
261
262
+ // Local Variables:
263
+ // mode: rust;
264
+ // fill-column: 78;
265
+ // indent-tabs-mode: nil
266
+ // c-basic-offset: 4
267
+ // buffer-file-coding-system: utf-8-unix
268
+ // compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
269
+ // End:
Original file line number Diff line number Diff line change @@ -84,6 +84,16 @@ fn test_init_elt() {
84
84
assert ( v. ( 5 ) == 20 u) ;
85
85
}
86
86
87
+ fn test_is_empty ( ) {
88
+ assert ivec:: is_empty[ int] ( ~[ ] ) ;
89
+ assert !ivec:: is_empty ( ~[ 0 ] ) ;
90
+ }
91
+
92
+ fn test_is_not_empty ( ) {
93
+ assert ivec:: is_not_empty ( ~[ 0 ] ) ;
94
+ assert !ivec:: is_not_empty[ int] ( ~[ ] ) ;
95
+ }
96
+
87
97
fn test_last ( ) {
88
98
auto n = ivec:: last ( ~[ ] ) ;
89
99
assert ( n == none) ;
@@ -240,6 +250,10 @@ fn main() {
240
250
test_reserve_and_on_heap ( ) ;
241
251
test_unsafe_ptrs ( ) ;
242
252
253
+ // Predicates
254
+ test_is_empty ( ) ;
255
+ test_is_not_empty ( ) ;
256
+
243
257
// Accessors
244
258
test_init_fn ( ) ;
245
259
test_init_elt ( ) ;
@@ -261,3 +275,12 @@ fn main() {
261
275
test_any_and_all ( ) ;
262
276
}
263
277
278
+ // Local Variables:
279
+ // mode: rust;
280
+ // fill-column: 78;
281
+ // indent-tabs-mode: nil
282
+ // c-basic-offset: 4
283
+ // buffer-file-coding-system: utf-8-unix
284
+ // compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
285
+ // End:
286
+
You can’t perform that action at this time.
0 commit comments