diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-05-10 11:37:25 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-05-10 11:37:25 -0400 |
| commit | 284ab109c4b83f7bb9a832f284f706e641b002fd (patch) | |
| tree | d7dc258a7e0676a9867e7941d8605074b57ea74a /std/array_list.zig | |
| parent | 7e37d268c86ccc823c4a381a42029722d36c3975 (diff) | |
| parent | efa39c5343e13a13e65210f55da5df23ee3feb3e (diff) | |
| download | zig-284ab109c4b83f7bb9a832f284f706e641b002fd.tar.gz zig-284ab109c4b83f7bb9a832f284f706e641b002fd.zip | |
Merge remote-tracking branch 'origin/master' into llvm7
Diffstat (limited to 'std/array_list.zig')
| -rw-r--r-- | std/array_list.zig | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/std/array_list.zig b/std/array_list.zig index bd7e8ea7ed..f1881cd7f3 100644 --- a/std/array_list.zig +++ b/std/array_list.zig @@ -28,11 +28,11 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ }; } - pub fn deinit(l: &Self) void { + pub fn deinit(l: &const Self) void { l.allocator.free(l.items); } - pub fn toSlice(l: &Self) []align(A) T { + pub fn toSlice(l: &const Self) []align(A) T { return l.items[0..l.len]; } @@ -150,7 +150,7 @@ pub fn AlignedArrayList(comptime T: type, comptime A: u29) type{ } }; - pub fn iterator(self: &Self) Iterator { + pub fn iterator(self: &const Self) Iterator { return Iterator { .list = self, .count = 0 }; } }; @@ -168,6 +168,14 @@ test "basic ArrayList test" { assert(list.items[i] == i32(i + 1)); }} + for (list.toSlice()) |v, i| { + assert(v == i32(i + 1)); + } + + for (list.toSliceConst()) |v, i| { + assert(v == i32(i + 1)); + } + assert(list.pop() == 10); assert(list.len == 9); @@ -228,4 +236,4 @@ test "insert ArrayList test" { const items = []const i32 { 1 }; try list.insertSlice(0, items[0..0]); assert(list.items[0] == 5); -}
\ No newline at end of file +} |
