alias T = int;
enum nBits = 8*T.sizeof;
T a = 0;
a.bts(0); assert(a == 1);
a.bts(1); assert(a == 3);
a.bts(2); assert(a == 7);
a.btr(0); assert(a == 6);
a.btr(1); assert(a == 4);
a.btr(2); assert(a == 0);
a.bts(0, 1, 2); assert(a == 7);
a.btr(0, 1, 2); assert(a == 0);
a.bts(8*T.sizeof - 1); assert(a != 0);
a.btr(8*T.sizeof - 1); assert(a == 0);
T b = 0;
b.bts(nBits - 1);
assert(b == T.min);
static void test(T)()
{
enum nBits = 8*T.sizeof;
T x = 0;
x.bts(0);
}
test!float;
test!double;
assert(makeBit!int(2) == 4);
assert(makeBit!int(2, 3) == 12);
assert(makeBit!uint(0, 31) == 2^^31 + 1);
import std.meta : AliasSeq;
foreach (T; AliasSeq!(ubyte, ushort, uint, ulong))
{
foreach (const n; 0 .. 8*T.sizeof)
{
const x = makeBit!T(n);
assert(x == 2UL^^n);
T y = x;
y.resetBit(n);
assert(y == 0);
y.setBit(n);
assert(y == x);
}
}