FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
C++
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
March 01, 2003

C++ Expression Templates

(Page 7 of 18)
March 2003/C++ Expression Templates

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 —
Previous Page | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 Next Page
RELATED ARTICLES
No Related Articles
TOP 5 ARTICLES
No Top Articles.



MICROSITES
FEATURED TOPIC

ADDITIONAL TOPICS

INFO-LINK