authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-10 16:57:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-11 10:33:54-07:00
logec67d6e03a05a2d87880d7a97654ae55f4c733a2
tree8a33f76030fea045e29cf50e9f30b29cd516cedc
parent41dbd0d0da0989495a97e99fb9269a49ac302768

std.MultiArrayList: add empty initalizer value


1 files changed, 7 insertions(+), 1 deletions(-)

lib/std/multi_array_list.zig+7-1
......@@ -23,6 +23,12 @@ pub fn MultiArrayList(comptime T: type) type {
2323 len: usize = 0,
2424 capacity: usize = 0,
2525
26 pub const empty: Self = .{
27 .bytes = undefined,
28 .len = 0,
29 .capacity = 0,
30 };
31
2632 const Elem = switch (@typeInfo(T)) {
2733 .@"struct" => T,
2834 .@"union" => |u| struct {
......@@ -474,7 +480,7 @@ pub fn MultiArrayList(comptime T: type) type {
474480 pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
475481 inline for (fields, 0..) |field_info, i| {
476482 if (@sizeOf(field_info.type) != 0) {
477 const field = @as(Field, @enumFromInt(i));
483 const field: Field = @enumFromInt(i);
478484 const ptr = sc.slice.items(field);
479485 mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
480486 }