zig/doc/langref/test_comptime_max_with_bool.zig

15 lines
278 B
Zig
Raw Normal View History

fn max(comptime T: type, a: T, b: T) T {
if (T == bool) {
return a or b;
} else if (a > b) {
return a;
} else {
return b;
}
}
test "try to compare bools" {
try @import("std").testing.expect(max(bool, false, true) == true);
}
// test