CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/PhysicsTools/Utilities/interface/Power.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_Utilities_Power_h
00002 #define PhysicsTools_Utilities_Power_h
00003 #include <boost/static_assert.hpp>
00004 #include <cmath>
00005 
00006 namespace funct {
00007   template<typename A, typename B>
00008   struct PowerStruct { 
00009     PowerStruct(const A & a, const B & b) : _1(a), _2(b) { }
00010     double operator()() const {
00011       return std::pow(_1(), _2());
00012     }
00013     operator double() const {
00014       return std::pow(_1(), _2());
00015     }
00016     double operator()(double x) const {
00017       return std::pow(_1(x), _2(x));
00018     }
00019     double operator()(double x, double y) const {
00020       return std::pow(_1(x, y), _2(x, y));
00021     }
00022     A _1; 
00023     B _2;
00024   };
00025 
00026   template<typename A, typename B>
00027   struct Power {
00028     typedef PowerStruct<A, B> type;
00029     static type combine(const A& a, const B& b) { 
00030       return type(a, b);
00031     }
00032   };
00033 
00034   template<typename A, typename B>
00035   inline typename Power<A, B>::type operator^(const A& a, const B& b) {
00036     return Power<A, B>::combine(a, b);
00037   }
00038   
00039   template<typename A, typename B>
00040   inline typename Power<A, B>::type pow(const A& a, const B& b) {
00041     return Power<A, B>::combine(a, b);
00042   }
00043 
00044 }
00045 
00046 #endif