Function CAST_OR_CALL [src]
A 2-argument function-like macro defined as #define FOO(A, B) (A)(B)
could be either: cast B to A, or call A with the value B.
Prototype
pub fn CAST_OR_CALL(a: anytype, b: anytype) switch (@typeInfo(@TypeOf(a))) { .type => a, .@"fn" => |fn_info| fn_info.return_type orelse void, else => |info| @compileError("Unexpected argument type: " ++ @tagName(info)), }
Source
pub fn CAST_OR_CALL(a: anytype, b: anytype) switch (@typeInfo(@TypeOf(a))) {
.type => a,
.@"fn" => |fn_info| fn_info.return_type orelse void,
else => |info| @compileError("Unexpected argument type: " ++ @tagName(info)),
} {
switch (@typeInfo(@TypeOf(a))) {
.type => return cast(a, b),
.@"fn" => return a(b),
else => unreachable, // return type will be a compile error otherwise
}
}