|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org */ 00023 00024 /* 00025 * Project: Algebra 00026 * Purpose: Allow to inline binary and unary operators. 00027 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00028 * 00029 **/ 00030 00037 #ifndef STK_TOPERATOR_H 00038 #define STK_TOPERATOR_H 00039 00040 #include "../../STKernel/include/STK_Real.h" 00041 00042 namespace STK 00043 { 00044 /* forward declaration.*/ 00045 template<class Op, class ExpLeft, class ExpRight> 00046 class BinOp; 00047 00048 template<class Op, class Exp> 00049 class UnOp; 00050 00051 00055 struct Plus 00056 { 00057 inline static Real apply(Real const& x, Real const& y) 00058 { return x+y;} 00059 }; 00060 00064 struct Minus 00065 { 00066 inline static Real apply(Real const& x, Real const& y) 00067 { return x-y;} 00068 }; 00069 00073 struct Mult 00074 { 00075 inline static Real apply(Real const& x, Real const& y) 00076 { return x*y;} 00077 }; 00078 00082 struct Div 00083 { 00084 inline static Real apply(Real const& x, Real const& y) 00085 { return x/y;} 00086 }; 00087 00091 struct Uplus 00092 { 00093 inline static Real apply(Real const& y) 00094 { return +y;} 00095 }; 00096 00100 struct Uminus 00101 { 00102 inline static Real apply(Real const& y) 00103 { return -y;} 00104 }; 00105 00106 /* These Operator construct the recursion. */ 00108 template< class ExpLeft, class ExpRight> 00109 BinOp<Plus, ExpLeft, ExpRight > 00110 operator+( const ExpLeft& lhs, const ExpRight& rhs) 00111 { return BinOp<Plus, ExpLeft, ExpRight >(lhs, rhs);} 00112 00114 template< class ExpLeft, class ExpRight> 00115 BinOp<Minus, ExpLeft, ExpRight > 00116 operator-( const ExpLeft& lhs, const ExpRight& rhs) 00117 { return BinOp<Minus, ExpLeft, ExpRight >(lhs, rhs);} 00118 00120 template< class ExpLeft, class ExpRight> 00121 BinOp<Mult, ExpLeft, ExpRight > 00122 operator*( const ExpLeft& lhs, const ExpRight& rhs) 00123 { return BinOp<Mult, ExpLeft, ExpRight >(lhs, rhs);} 00124 00126 template< class ExpLeft, class ExpRight> 00127 BinOp<Div, ExpLeft, ExpRight > 00128 operator/( const ExpLeft& lhs, const ExpRight& rhs) 00129 { return BinOp<Div, ExpLeft, ExpRight >(lhs, rhs);} 00130 00132 template<class ExpRight> 00133 UnOp<Uminus, ExpRight > operator-(const ExpRight& rhs) 00134 { return UnOp<Uminus, ExpRight >(rhs);} 00135 00137 template<class ExpRight> 00138 UnOp<Uplus, ExpRight > operator+(const ExpRight& rhs) 00139 { return UnOp<Uplus, ExpRight >(rhs);} 00140 00141 } // namespace STK 00142 00143 #endif /*STK_TOPERATOR_H*/