Understanding C++ Expression Templates - Angelika Langer
Understanding C++ Expression Templates - Angelika Langer
Understanding C++ Expression Templates - Angelika Langer
- No tags were found...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
25Implementation Using <strong>Templates</strong>ExprT1, ExprT2, BinOpBinaryExprExprT1 e1ExprT2 e2BinOp opinterpret()op(e1.interpret(),e2.interpret())ExprT, , OpUnaryExprExprT e1Op opinterpret()op(e.interpret())«template argument»Literalconst double vinterpret()vVariabledouble& vinterpret()v«template argument»© Copyright 1995-2000 by <strong>Angelika</strong> <strong>Langer</strong>. All Rights Reserved.http://www.<strong>Angelika</strong><strong>Langer</strong>.com(49)last update: 11/7/2005 ,21:37The Terminal <strong>Expression</strong>sclass Literal {public:Literal(const double v) : _val(v) {}double eval() const { return _val; }private:const double _val;};class Variable {public:Variable(double& v) : _val(v) {}double eval() const { return _val; }private:double& _val;};© Copyright 1995-2000 by <strong>Angelika</strong> <strong>Langer</strong>. All Rights Reserved.http://www.<strong>Angelika</strong><strong>Langer</strong>.com(50)last update: 11/7/2005 ,21:37