#include #include #include #include using namespace std; using BinBoolOp = bool(bool, bool); bool operator==(function f, function g) { for (bool x: {false, true}) for (bool y: {false, true}) if (f(x, y) != g(x, y)) return false; return true; } bool commutative(function f) { using namespace placeholders; return f == bind(f, _2, _1); } void tabulate(ostream &stream, string fn, function f) { int w = max(1, static_cast(fn.size())); stream << setw(w) << fn; for (bool y: {false, true}) stream << setw(2) << y; stream << endl; for (bool x: {false, true}) { stream << setw(w) << x; for (bool y: {false, true}) { stream << setw(2) << f(x, y); } stream << endl; } stream << "Kommutativ: " << commutative(f) << endl; } bool logical_implies(bool a, bool b) { return !a || b; // Äquivalent: a <= b } int main() { tabulate(cout, "&", bit_and()); cout << endl; tabulate(cout, "|", bit_or()); cout << endl; tabulate(cout, "^", bit_xor()); cout << endl; tabulate(cout, "=>", logical_implies); }