enum A { None, A = 1 << 0, B = 1 << 1, C = 1 << 2, D = 1 << 3, } static assert(isBitFlagEnum!A);
Test an enum with default (consecutive) values
enum B { A, B, C, D // D == 3 } static assert(!isBitFlagEnum!B);
Test an enum with non-integral values
enum C: double { A = 1 << 0, B = 1 << 1 } static assert(!isBitFlagEnum!C);
Detect whether an enum is of integral type and has only "flag" values (i.e. values with a bit count of exactly 1). Additionally, a zero value is allowed for compatibility with enums including a "None" value.