1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <concepts>
#include <iostream>
template<typename... Args>
requires (sizeof ...(Args) > 1) && (std::convertible_to<Args, bool> && ...)
bool And(Args... args)
{
return (... && args);
}
template<typename... Args>
bool Nand(Args... args) {
return !And(args...);
}
bool evaluate(bool selb, bool sela, bool D, bool C, bool B, bool A) {
const auto notb { Nand(selb, selb) };
const auto nota { Nand(sela, sela) };
return Nand(Nand(A, notb, nota), Nand(B, notb, sela), Nand(C, nota, selb), Nand(D, selb, sela));
}
int main() {
std::cout << "b a D C B A Q\n";
for (bool b : {0, 1})
for (bool a : {0, 1})
for (bool D : {0, 1})
for (bool C : {0, 1})
for (bool B : {0, 1})
for (bool A : {0, 1})
if (auto Q { evaluate(b, a, D, C, B, A) }; Q)
std::cout << b << ' ' << a << ' ' << D << ' ' << C << ' ' << B << ' ' << A << " " << Q << '\n';
}
| |