有没有可能在zig中创建一个comptime函数来生成一个新的结构类型?该函数将接收字符串数组和类型数组。字符串是后续结构字段的名称。
发布于 2020-05-02 10:58:42
不是。这在https://github.com/ziglang/zig/issues/383已经提出很久了
发布于 2020-09-12 17:38:55
现在已经实现为https://github.com/ziglang/zig/pull/6099
const builtin = @import("std").builtin;
const A = @Type(.{
.Struct = .{
.layout = .Auto,
.fields = &[_]builtin.TypeInfo.StructField{
.{ .name = "one", .field_type = i32, .default_value = null, .is_comptime = false, .alignment = 0 },
},
.decls = &[_]builtin.TypeInfo.Declaration{},
.is_tuple = false,
},
});
test "" {
const a: A = .{ .one = 25 };
}TypeInfo结构被定义为here。
https://stackoverflow.com/questions/61466724
复制相似问题