1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4const StructOfSlices = extras.StructOfSlices;
5const StructOfArrays = extras.StructOfArrays;
6const expectSimilarType = extras.expectSimilarType;
7
8pub fn StaticMultiList(T: type) type {
9 return struct {
10 items: StructOfSlices(T),
11
12 pub fn initComptime(comptime data: []const T) @This() {
13 return comptime blk: {
14 @setEvalBranchQuota(1_000_000_000);
15 var temp: StructOfArrays(data.len, T) = undefined;
16 for (data, 0..) |item, i| {
17 for (std.meta.fieldNames(T)) |name| {
18 @field(temp, name)[i] = @field(item, name);
19 }
20 }
21 var result: @This() = undefined;
22 for (std.meta.fields(T)) |field| {
23 const constant = @field(temp, field.name)[0..data.len].*;
24 @field(result.items, field.name) = &constant;
25 }
26 break :blk result;
27 };
28 }
29 };
30}
31
32test {
33 try expectSimilarType(
34 StaticMultiList(struct {
35 x: u8,
36 y: u16,
37 }),
38 struct {
39 items: struct {
40 x: []const u8,
41 y: []const u16,
42 },
43 },
44 );
45}