00001 #ifndef PhysicsTools_Utilities_Sgn_h 00002 #define PhysicsTools_Utilities_Sgn_h 00003 00004 namespace funct { 00005 00006 template<typename T> 00007 struct SgnStruct { 00008 SgnStruct(const T& t) : _(t) { } 00009 inline double operator()() const { return _() >= 0 ? 1 : -1; } 00010 inline operator double() const { return _() >= 0 ? 1 : -1; } 00011 T _; 00012 }; 00013 00014 template<typename T> 00015 struct Sgn { 00016 typedef SgnStruct<T> type; 00017 inline static type compose(const T& t) { return type(t); } 00018 }; 00019 00020 template<typename T> 00021 inline typename Sgn<T>::type sgn(const T & t) { 00022 return Sgn<T>::compose(t); 00023 } 00024 00025 } 00026 00027 #endif