在 Zig 0.9 中,我需要一个类型为 的文字表达式void,用作 的上下文参数std.sort.sort,以便我的lessThan函数签名在语义上准确。有一些吗?
我尝试了这些但没有效果:
const ek = @import("std").io.getStdOut().writer();
test "void" {
const kandidati = .{ type, u0, .{}, void, null, undefined };
inline for (kandidati) |k|
try ek.print("{}, ", .{@TypeOf(k)});
try ek.print("\n", .{});
}
Run Code Online (Sandbox Code Playgroud)
给予
Test [0/1] test "void"... type, type, struct:31:37, type, @Type(.Null), @Type(.Undefined),
All 1 tests passed.
Run Code Online (Sandbox Code Playgroud)
我不想使用像const v: void = undefined;;这样的虚拟变量 这太冗长了。
作为参考,使用带有类型参数的函数void作为上下文参数,会给出如下错误消息std.sort.sortlessThanvoid
error: expected type 'fn(type,anytype,anytype) anytype', found 'fn(void, Type1, Type1) bool'
Run Code Online (Sandbox Code Playgroud)