The compile-time numbers to generate a static truth table from.
A truth table as a static array of booleans.
const table = truthTable!(1, 3, 5); assert(is(typeof(table) : bool[6])); assert(table == [ false, true, false, true, false, true ]); assert(table == [ 0, 1, 0, 1, 0, 1 ]); assert(!table[0]); assert( table[1]); assert(!table[2]); assert( table[3]); assert(!table[4]); assert( table[5]);
import std.conv : to; { static immutable table = truthTable!(1, 3, 5); static assert(is(typeof(table) : bool[6]), typeof(table).stringof); static assert((table == [ false, true, false, true, false, true ]), table.to!string); static assert((table == [ 0, 1, 0, 1, 0, 1 ]), table.to!string); static assert(!table[0]); static assert( table[1]); static assert(!table[2]); static assert( table[3]); static assert(!table[4]); static assert( table[5]); } { enum E { a, b, c, d, e } static immutable table = truthTable!(E.b, E.c); static assert(is(typeof(table) : bool[3]), typeof(table).stringof); static assert((table == [ false, true, true ]), table.to!string); static assert((table == [ 0, 1, 1 ]), table.to!string); static assert(!table[E.a]); static assert( table[E.b]); static assert( table[E.c]); }
Generates a static truth table from a list of compile-time numbers.
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.
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 values of the numbers passed.