What literal expression has type `void`?
In Zig 0.9, I need a literal expression that has type void
, for use as the context parameter to std.sort.sort
, so that my lessThan
function signature is semantically accurate. Is there some?
I tried these but to no avail:
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", .{});
}
giving
Test [0/1] test "void"... type, type, struct:31:37, type, @Type(.Null), @Type(.Undefined),
All 1 tests passed.
I don't want to use a dummy variable like const v: void = undefined;
; that's too verbose.
For reference, using void
as the context parameter to std.sort.sort
with a lessThan
function that takes a parameter of type void
, gives an error message like
error: expected type 'fn(type,anytype,anytype) anytype', found 'fn(void, Type1, Type1) bool'
The expressions void{}
, @as(void, undefined)
, and {}
have type void
, for example. You can see {}
used in the standard library test cases for std.sort.sort
.
The "canonical" way of getting the void value is to use an empty block.