Skip to content

Commit cd31f7c

Browse files
committed
---
yaml --- r: 3926 b: refs/heads/master c: 139aaa1 h: refs/heads/master v: v3
1 parent f774a2a commit cd31f7c

File tree

3 files changed

+44
-1
lines changed

3 files changed

+44
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8afb1a7c639d2d2959cdc79c544fac7dd5730897
2+
refs/heads/master: 139aaa1616fd341a71f0f11adb4e8850639e228c

trunk/src/lib/ivec.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ fn init_elt_mut[T](&T t, uint n_elts) -> T[mutable] {
7272
ret v;
7373
}
7474

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+
}
7587

7688
// Accessors
7789

@@ -247,3 +259,11 @@ mod unsafe {
247259
}
248260
}
249261

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:

trunk/src/test/run-pass/lib-ivec.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ fn test_init_elt() {
8484
assert (v.(5) == 20u);
8585
}
8686

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+
8797
fn test_last() {
8898
auto n = ivec::last(~[]);
8999
assert (n == none);
@@ -240,6 +250,10 @@ fn main() {
240250
test_reserve_and_on_heap();
241251
test_unsafe_ptrs();
242252

253+
// Predicates
254+
test_is_empty();
255+
test_is_not_empty();
256+
243257
// Accessors
244258
test_init_fn();
245259
test_init_elt();
@@ -261,3 +275,12 @@ fn main() {
261275
test_any_and_all();
262276
}
263277

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+

0 commit comments

Comments
 (0)