Listing 10: The modified classes and their use for calculating the Gauss distribution
class Literal { public: Literal(double v) : _val(v) {} double eval(double) const { return _val; } private: const double _val; }; class Identity { public: double eval(double d) const { return d; } }; template <class ExprT1,class ExprT2, class BinOp> class BinExpr { public: double eval(double d) const { return _op(_expr1.eval(d),_expr2.eval(d)); } }; ... template <class ExprT1,class ExprT2, class BinOp> class BinaryExpr { public: BinaryExpr(ExprT1 e1, ExprT2 e2,BinOp op=BinOp()) : _expr1(e1),_expr2(e2),_op(op) {} double eval() const { return _op(_expr1.eval(),_expr2.eval()); } private: exprTraits<ExprT1>::expr_type _expr1; exprTraits<ExprT2>::expr_type _expr2; BinOp _op; }; End of Listing