From fb2f0cc497c0af897a3d2dd3f612e50522368221 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Tue, 12 Nov 2019 09:14:38 +0100 Subject: [PATCH] ArrayList: ptrAt function returns pointer to item at given index --- lib/std/array_list.zig | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/std/array_list.zig b/lib/std/array_list.zig index 444de30162..64f13eff9b 100644 --- a/lib/std/array_list.zig +++ b/lib/std/array_list.zig @@ -71,6 +71,11 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type { return self.toSliceConst()[i]; } + /// Safely access ptr to index i of the list. + pub fn ptrAt(self: Self, i: usize) *T { + return &self.toSlice()[i]; + } + /// Sets the value at index `i`, or returns `error.OutOfBounds` if /// the index is not in range. pub fn setOrError(self: Self, i: usize, item: T) !void {