std.MultiArrayList: add empty initalizer value

This commit is contained in:
Andrew Kelley 2024-10-10 16:57:41 -07:00
parent 41dbd0d0da
commit ec67d6e03a

View File

@ -23,6 +23,12 @@ pub fn MultiArrayList(comptime T: type) type {
len: usize = 0,
capacity: usize = 0,
pub const empty: Self = .{
.bytes = undefined,
.len = 0,
.capacity = 0,
};
const Elem = switch (@typeInfo(T)) {
.@"struct" => T,
.@"union" => |u| struct {
@ -474,7 +480,7 @@ pub fn MultiArrayList(comptime T: type) type {
pub fn swap(sc: @This(), a_index: usize, b_index: usize) void {
inline for (fields, 0..) |field_info, i| {
if (@sizeOf(field_info.type) != 0) {
const field = @as(Field, @enumFromInt(i));
const field: Field = @enumFromInt(i);
const ptr = sc.slice.items(field);
mem.swap(field_info.type, &ptr[a_index], &ptr[b_index]);
}