00001 #ifndef PhysicsTools_Utilities_Ratio_h 00002 #define PhysicsTools_Utilities_Ratio_h 00003 #include <boost/static_assert.hpp> 00004 00005 namespace funct { 00006 template<typename A, typename B> 00007 struct RatioStruct { 00008 RatioStruct(const A & a, const B & b) : _1(a), _2(b) { } 00009 double operator()() const { 00010 return _1() / _2(); 00011 } 00012 operator double() const { 00013 return _1() / _2(); 00014 } 00015 double operator()(double x) const { 00016 return _1(x) / _2(x); 00017 } 00018 double operator()(double x, double y) const { 00019 return _1(x, y) / _2(x, y); 00020 } 00021 A _1; 00022 B _2; 00023 }; 00024 00025 template<typename A, typename B> 00026 struct Ratio{ 00027 typedef RatioStruct<A, B> type; 00028 static type combine(const A& a, const B& b) { 00029 return type(a, b); 00030 } 00031 }; 00032 00033 template<typename A, typename B> 00034 inline typename Ratio<A, B>::type operator/(const A& a, const B& b) { 00035 return Ratio<A, B>::combine(a, b); 00036 } 00037 00038 } 00039 00040 #endif