diff options
| author | xackus <14938807+xackus@users.noreply.github.com> | 2020-04-11 21:06:56 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-04-11 20:40:34 -0400 |
| commit | dbc00e24247da16ac584bb9e92b5ccf04647c3b9 (patch) | |
| tree | a73219b06cb0ead18b93289975257f2f498f5dd4 /lib/std/array_list.zig | |
| parent | 3c34c313cf999238753b34f01b0437a552fb3be0 (diff) | |
| download | zig-dbc00e24247da16ac584bb9e92b5ccf04647c3b9.tar.gz zig-dbc00e24247da16ac584bb9e92b5ccf04647c3b9.zip | |
ArrayList: remove old (before span) API
Diffstat (limited to 'lib/std/array_list.zig')
| -rw-r--r-- | lib/std/array_list.zig | 86 |
1 files changed, 9 insertions, 77 deletions
diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index c6bb5bf3e7..4d3005e4e4 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -57,37 +57,13 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return self.items; } - /// Deprecated: use `items` field directly. - pub fn toSlice(self: Self) Slice { - return self.items; - } - - /// Deprecated: use `items` field directly. - pub fn toSliceConst(self: Self) SliceConst { - return self.items; - } - - /// Deprecated: use `list.items[i]`. - pub fn at(self: Self, i: usize) T { - return self.items[i]; - } - - /// Deprecated: use `&list.items[i]`. - pub fn ptrAt(self: Self, i: usize) *T { - return &self.items[i]; - } - - /// Deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.items[i] = item`. - pub fn setOrError(self: Self, i: usize, item: T) !void { - if (i >= self.items.len) return error.OutOfBounds; - self.items[i] = item; - } - - /// Deprecated: use `list.items[i] = item`. - pub fn set(self: *Self, i: usize, item: T) void { - assert(i < self.items.len); - self.items[i] = item; - } + pub const toSlice = @compileError("deprecated: use `items` field directly"); + pub const toSliceConst = @compileError("deprecated: use `items` field directly"); + pub const at = @compileError("deprecated: use `list.items[i]`"); + pub const ptrAt = @compileError("deprecated: use `&list.items[i]`"); + pub const setOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.items[i] = item`"); + pub const set = @compileError("deprecated: use `list.items[i] = item`"); + pub const swapRemoveOrError = @compileError("deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.swapRemove(i)`"); /// ArrayList takes ownership of the passed in slice. The slice must have been /// allocated with `allocator`. @@ -167,12 +143,6 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return old_item; } - /// Deprecated: use `if (i >= list.items.len) return error.OutOfBounds else list.swapRemove(i)`. - pub fn swapRemoveOrError(self: *Self, i: usize) !T { - if (i >= self.items.len) return error.OutOfBounds; - return self.swapRemove(i); - } - /// Append the slice of items to the list. Allocates more /// memory as necessary. pub fn appendSlice(self: *Self, items: SliceConst) !void { @@ -308,9 +278,6 @@ test "std.ArrayList.basic" { var list = ArrayList(i32).init(testing.allocator); defer list.deinit(); - // setting on empty list is out of bounds - testing.expectError(error.OutOfBounds, list.setOrError(0, 1)); - { var i: usize = 0; while (i < 10) : (i += 1) { @@ -329,10 +296,6 @@ test "std.ArrayList.basic" { testing.expect(v == @intCast(i32, i + 1)); } - for (list.toSliceConst()) |v, i| { - testing.expect(v == @intCast(i32, i + 1)); - } - testing.expect(list.pop() == 10); testing.expect(list.items.len == 9); @@ -347,11 +310,8 @@ test "std.ArrayList.basic" { testing.expect(list.items.len == 9); // can only set on indices < self.items.len - list.set(7, 33); - list.set(8, 42); - - testing.expectError(error.OutOfBounds, list.setOrError(9, 99)); - testing.expectError(error.OutOfBounds, list.setOrError(10, 123)); + list.items[7] = 33; + list.items[8] = 42; testing.expect(list.pop() == 42); testing.expect(list.pop() == 33); @@ -428,34 +388,6 @@ test "std.ArrayList.swapRemove" { testing.expect(list.items.len == 4); } -test "std.ArrayList.swapRemoveOrError" { - var list = ArrayList(i32).init(testing.allocator); - defer list.deinit(); - - // Test just after initialization - testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0)); - - // Test after adding one item and remote it - try list.append(1); - testing.expect((try list.swapRemoveOrError(0)) == 1); - testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0)); - - // Test after adding two items and remote both - try list.append(1); - try list.append(2); - testing.expect((try list.swapRemoveOrError(1)) == 2); - testing.expect((try list.swapRemoveOrError(0)) == 1); - testing.expectError(error.OutOfBounds, list.swapRemoveOrError(0)); - - // Test out of bounds with one item - try list.append(1); - testing.expectError(error.OutOfBounds, list.swapRemoveOrError(1)); - - // Test out of bounds with two items - try list.append(2); - testing.expectError(error.OutOfBounds, list.swapRemoveOrError(2)); -} - test "std.ArrayList.insert" { var list = ArrayList(i32).init(testing.allocator); defer list.deinit(); |
