bits

Get a view or copy of num that supports bitwise operations.

Useful in generic code that handles both basic types and checkedint types.

  1. N bits [@property getter]
  2. SmartInt!(BasicScalar!N, N.policy, Yes.bitOps) bits [@property getter]
    @safe @property
    SmartInt!(BasicScalar!N, N.policy, Yes.bitOps)
    bits
    (
    N
    )
    (
    const N num
    )
  3. SafeInt!(BasicScalar!N, N.policy, Yes.bitOps) bits [@property getter]

Examples

import checkedint.throws : SmartInt; // use IntFlagPolicy.throws

assert(is(typeof(bits(5)) == int));

SmartInt!(int, No.bitOps) noBits = 5;
assert(is(typeof(bits(noBits)) == SmartInt!(int, Yes.bitOps)));

static assert(!__traits(compiles, noBits << 2));
assert((bits(noBits) << 2) == 20);

Meta