Whether to generate a truth table for the full enum range.
The enum values to generate a truth table from.
A truth table as an array of booleans.
enum E { a, b, c, d, e } const table = truthTable!(E.b, E.c); assert(is(typeof(table) : bool[__traits(allMembers, E).length])); assert(!table[E.a]); assert( table[E.b]); assert( table[E.c]); assert(!table[E.d]); assert(!table[E.e]); const staticTable = truthTable!(Yes.fullEnumRange, E.c, E.d); assert(is(typeof(staticTable) : bool[__traits(allMembers, E).length])); assert(staticTable == [ false, false, true, true, false ]); assert(staticTable == [ 0, 0, 1, 1, 0 ]);
enum E { a, b, c, d, e } static immutable table = truthTable!(Yes.fullEnumRange, E.b, E.c); static assert(is(typeof(table) : bool[__traits(allMembers, E).length]), typeof(table).stringof); static assert((table == [ false, true, true, false, false ]), table.to!string); static assert((table == [ 0, 1, 1, 0, 0 ]), table.to!string); static assert(!table[E.a]); static assert( table[E.b]); static assert( table[E.c]); static assert(!table[E.d]); static assert(!table[E.e]);
Generates a static truth table from a list of compile-time enum values.
The table is a static array of booleans, where each index corresponds to a number in the input list. The boolean at each index is true if the number is in the input list, and false otherwise.
If Yes.fullEnumRange is passed, the returned table will be sized to accommodate the highest value in the enum. If No.fullEnumRange is passed, the returned table will be sized to accommodate the highest value in the input list.
Note: This is not a sparse array and will be as large as requested. In addition it is stack-allocated, so be mindful of the size of the numbers passed.