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. inout(N) bits [@property getter]
  2. inout(N) bits [@property getter]
  3. N bits [@property getter]
  4. SmartInt!(BasicScalar!N, N.policy, Yes.bitOps) bits [@property getter]
  5. SafeInt!(BasicScalar!N, N.policy, Yes.bitOps) bits [@property getter]
    @property
    SafeInt!(BasicScalar!N, N.policy, Yes.bitOps)
    bits
    @safe
    (
    N
    )
    (
    const N num
    )
    if (
    isSafeInt!N
    )

Examples

1 import checkedint.throws : SmartInt; // use IntFlagPolicy.throws
2 
3 assert(is(typeof(bits(5)) == int));
4 
5 SmartInt!(int, No.bitOps) noBits = 5;
6 assert(is(typeof(bits(noBits)) == SmartInt!(int, Yes.bitOps)));
7 
8 static assert(!__traits(compiles, noBits << 2));
9 assert((bits(noBits) << 2) == 20);

Meta