test144
auto test144 =
q{--- test144
// select function
@extern(module, "host")
void printStr(u8[]);
@extern(module, "host")
void printInt(i64 i);
bool isInteger($type type) {
return type == u8
|| type == i8
|| type == u16
|| type == i16
|| type == u32
|| type == i32
|| type == u64
|| type == i64;
}
$alias selectPrintFunc($type T) {
if (isInteger(T))
return printInt;
if ($isSlice(T))
return printStr;
$compileError("Invalid type");
}
void run() {
alias func1 = selectPrintFunc(u8[]);
func1("Hello");
alias func2 = selectPrintFunc(i32);
func2(42);
}
};
tests passing
functionsvariables