mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 09:03:12 +00:00
parent
4fc6f631e0
commit
482424e2b1
@ -28,8 +28,11 @@ pub fn MultiArrayList(comptime S: type) type {
|
||||
capacity: usize,
|
||||
|
||||
pub fn items(self: Slice, comptime field: Field) []FieldType(field) {
|
||||
const byte_ptr = self.ptrs[@enumToInt(field)];
|
||||
const F = FieldType(field);
|
||||
if (self.len == 0) {
|
||||
return &[_]F{};
|
||||
}
|
||||
const byte_ptr = self.ptrs[@enumToInt(field)];
|
||||
const casted_ptr = @ptrCast([*]F, @alignCast(@alignOf(F), byte_ptr));
|
||||
return casted_ptr[0..self.len];
|
||||
}
|
||||
@ -300,6 +303,8 @@ test "basic usage" {
|
||||
var list = MultiArrayList(Foo){};
|
||||
defer list.deinit(ally);
|
||||
|
||||
testing.expectEqual(@as(usize, 0), list.items(.a).len);
|
||||
|
||||
try list.ensureCapacity(ally, 2);
|
||||
|
||||
list.appendAssumeCapacity(.{
|
||||
|
Loading…
Reference in New Issue
Block a user