pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt MaskInt: typevalue: bool1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714pub inline fn boolMask(comptime MaskInt: type, value: bool) MaskInt {
if (@typeInfo(MaskInt) != .int)
@compileError("boolMask requires an integer mask type.");
if (MaskInt == u0)
@compileError("boolMask cannot convert to u0, it is too small.");
// The u1 and i1 cases tend to overflow,
// so we special case them here.
if (MaskInt == u1) return @intFromBool(value);
if (MaskInt == i1) {
// The @as here is a workaround for #7950
return @as(i1, @bitCast(@as(u1, @intFromBool(value))));
}
return -%@as(MaskInt, @intCast(@intFromBool(value)));
}