#include struct Add { template static auto eval(T lhs, T rhs) { return lhs + rhs; } }; struct Mul { template static auto eval(T lhs, T rhs) { return lhs * rhs; } }; template class Value { T _value; public: Value(T value): _value(value) {} auto eval() const { return _value; } }; template struct BinExpr { LHS lhs; RHS rhs; auto eval() const { return Op::eval(lhs.eval(), rhs.eval()); } }; int main() { using SubExpr = BinExpr, Value>; using MyExpr = BinExpr, SubExpr>; int volatile v0 = 3, v1 = 5, v2 = 7; int result; MyExpr expr{{v0}, {{v1}, {v2}}}; result = expr.eval(); std::printf("%d\n", result); }