Given a truth table with 5 inputs and one output, with a function prototype like:
bool compute(bool in1, bool in2, bool in3, bool in4, bool in5);
Is there somewhere, in the STL or other library, a class that allows to easily and efficiently manage the implementation of such a function?
In particular, the idea would be to be able to easily code the truth table with a kind of array like this:
some_type truth_table = [[0,0,0,0,0,0],
[0,0,0,0,1,1],
[0,0,0,1,0,1]
...];
Ideally, the class could "optimize" the truth table by avoiding unnecessary row evaluation.
This post and this post start to answer the question but using custom macros/implems.
If you want to check if all the supplied values are
true, you could make a variadic function template and do a fold over logical AND:A 1D array version could look like this:
For arrays with an arbitraty number of dimensions:
All of the above makes use of short-circuit evaluation and will stop the comparison at the first
falseencountered.