00001 #ifndef PhysicsTools_Utilities_Abs_h 00002 #define PhysicsTools_Utilities_Abs_h 00003 #include <cmath> 00004 00005 namespace funct { 00006 00007 template<typename T> 00008 struct AbsStruct { 00009 AbsStruct(const T& t) : _(t) { } 00010 inline double operator()() const { return ::fabs(_()); } 00011 inline operator double() const { return ::fabs(_()); } 00012 T _; 00013 }; 00014 00015 template<typename T> 00016 struct Abs { 00017 typedef AbsStruct<T> type; 00018 inline static type compose(const T& t) { return type(t); } 00019 }; 00020 00021 template<typename T> 00022 inline typename Abs<T>::type abs(const T & t) { 00023 return Abs<T>::compose(t); 00024 } 00025 00026 } 00027 00028 #endif