authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-06-21 18:54:33 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-06-21 18:54:33 -07:00
log362b148d5763fa3d99d9c4c4c822e233a65fb48d
treeac58e71584556106daa2e906295904f2db8b6cc9
parent4fe97f8f42ae9cf88ef90706d39bcc2bb5a94a10

add join


2 files changed, 31 insertions(+), 0 deletions(-)

src/join.zig created+30
......@@ -0,0 +1,30 @@
1const std = @import("std");
2const string = []const u8;
3const extras = @import("./lib.zig");
4
5pub fn join(input: anytype) Join(@TypeOf(input)) {
6 const T = @TypeOf(input);
7 var x: Join(T) = undefined;
8 inline for (std.meta.fields(T)) |item| {
9 inline for (std.meta.fields(item.type)) |f| {
10 @field(x, f.name) = @field(@field(input, item.name), f.name);
11 }
12 }
13 return x;
14}
15
16pub fn Join(comptime T: type) type {
17 var fields: []const std.builtin.Type.StructField = &.{};
18 inline for (std.meta.fields(T)) |item| {
19 inline for (std.meta.fields(item.type)) |f| {
20 fields = fields ++ &[_]std.builtin.Type.StructField{.{
21 .name = f.name,
22 .type = f.type,
23 .default_value_ptr = null,
24 .is_comptime = false,
25 .alignment = @alignOf(f.type),
26 }};
27 }
28 }
29 return @Type(.{ .@"struct" = .{ .layout = .auto, .fields = fields, .decls = &.{}, .is_tuple = false } });
30}
src/lib.zig+1
......@@ -106,3 +106,4 @@ pub usingnamespace @import("./hasFields.zig");
106106pub usingnamespace @import("./StructOfSlices.zig");
107107pub usingnamespace @import("./StructOfArrays.zig");
108108pub usingnamespace @import("./StaticMultiList.zig");
109pub usingnamespace @import("./join.zig");