| ... | ... | @@ -116,13 +116,21 @@ pub fn BoundedArrayAligned( |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /// Resize the slice, adding `n` new elements, which have `undefined` values. |
| 119 | | /// The return value is a slice pointing to the uninitialized elements. |
| 119 | /// The return value is a pointer to the array of uninitialized elements. |
| 120 | 120 | pub fn addManyAsArray(self: *Self, comptime n: usize) error{Overflow}!*align(alignment) [n]T { |
| 121 | 121 | const prev_len = self.len; |
| 122 | 122 | try self.resize(self.len + n); |
| 123 | 123 | return self.slice()[prev_len..][0..n]; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | /// Resize the slice, adding `n` new elements, which have `undefined` values. |
| 127 | /// The return value is a slice pointing to the uninitialized elements. |
| 128 | pub fn addManyAsSlice(self: *Self, n: usize) error{Overflow}![]align(alignment) T { |
| 129 | const prev_len = self.len; |
| 130 | try self.resize(self.len + n); |
| 131 | return self.slice()[prev_len..][0..n]; |
| 132 | } |
| 133 | |
| 126 | 134 | /// Remove and return the last element from the slice. |
| 127 | 135 | /// Asserts the slice has at least one item. |
| 128 | 136 | pub fn pop(self: *Self) T { |
| ... | ... | @@ -382,6 +390,10 @@ test BoundedArray { |
| 382 | 390 | try testing.expectEqual(swapped, 0xdd); |
| 383 | 391 | try testing.expectEqual(a.get(0), 0xee); |
| 384 | 392 | |
| 393 | const added_slice = try a.addManyAsSlice(3); |
| 394 | try testing.expectEqual(added_slice.len, 3); |
| 395 | try testing.expectEqual(a.len, 36); |
| 396 | |
| 385 | 397 | while (a.popOrNull()) |_| {} |
| 386 | 398 | const w = a.writer(); |
| 387 | 399 | const s = "hello, this is a test string"; |