isPow2F

ditto, avoids a jump instruction.

  1. bool isPow2E(T x)
  2. bool isPow2F(T x)
    bool
    isPow2F
    (
    T
    )
    (
    T x
    )
    if (
    isIntegral!T
    )

Examples

1 import std.meta : AliasSeq;
2 foreach (fn; AliasSeq!(isPow2, isPow2A, isPow2D, isPow2E, isPow2F))
3 {
4     // run-time
5     assert(!fn(7));
6     assert(fn(8));
7     assert(!fn(9));
8 
9     // compile-time
10     static assert(!fn(7));
11     static assert(fn(8));
12     static assert(!fn(9));
13 
14     assert(!fn(0));
15     assert(fn(1));
16     assert(fn(2));
17     assert(!fn(3));
18     assert(fn(4));
19     assert(!fn(5));
20     assert(!fn(6));
21     assert(!fn(7));
22     assert(fn(8));
23 }

Meta