authorgravatar for benoit.giannangeli@boursorama.frBenoit Giannangeli <benoit.giannangeli@boursorama.fr> 2019-11-12 09:14:38+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-29 18:46:59-05:00
logfb2f0cc497c0af897a3d2dd3f612e50522368221
treee8458f50e9d6c5ee97d18192df8749a930cece2c
parent54231e832bae780c5012fc5cd30932447f1e1d47

ArrayList: ptrAt function returns pointer to item at given index


1 files changed, 5 insertions(+), 0 deletions(-)

lib/std/array_list.zig+5
...@@ -71,6 +71,11 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {...@@ -71,6 +71,11 @@ pub fn AlignedArrayList(comptime T: type, comptime alignment: ?u29) type {
71 return self.toSliceConst()[i];71 return self.toSliceConst()[i];
72 }72 }
7373
74 /// Safely access ptr to index i of the list.
75 pub fn ptrAt(self: Self, i: usize) *T {
76 return &self.toSlice()[i];
77 }
78
74 /// Sets the value at index `i`, or returns `error.OutOfBounds` if79 /// Sets the value at index `i`, or returns `error.OutOfBounds` if
75 /// the index is not in range.80 /// the index is not in range.
76 pub fn setOrError(self: Self, i: usize, item: T) !void {81 pub fn setOrError(self: Self, i: usize, item: T) !void {