Enum member isBitFlagEnum

Determines whether E is a enum, whose members can be used as bit flags.

enum isBitFlagEnum(E) = allSatisfy!(isValid, EnumMembers!E);

This is the case if all members of E are integral numbers that are either 0 or positive integral powers of 2.

Parameters

NameDescription
E Some enum.

Returns

true if E contains only bit flags, false otherwise.

Example

enum Valid
{
    none = 0,
    one = 1 << 0,
    two = 1 << 1,
}
static assert(isBitFlagEnum!Valid);

enum Invalid
{
    one,
    two,
    three,
    four,
}
static assert(!isBitFlagEnum!Invalid);

enum Negative
{
    one = -1,
    two = -2,
}
static assert(!isBitFlagEnum!Negative);