// -*- C++ -*- // CLASSDOC OFF // $Id: TemplateFunctions.h,v 1.1 2004/01/12 09:03:54 mjg Exp $ // --------------------------------------------------------------------------- // CLASSDOC ON // // This file is a part of the CLHEP - a Class Library for High Energy Physics. // // This file contains template definitions of some usefull functions. // #ifndef HEP_TEMPLATEFUNCTIONS_H #define HEP_TEMPLATEFUNCTIONS_H #include "CLHEP/config/CLHEP.h" #ifndef CLHEP_MAX_MIN_DEFINED #define CLHEP_MAX_MIN_DEFINED #ifdef max #undef max #endif #ifdef min #undef min #endif template inline const T& max(const T& a, const T& b) { // Break this into two lines to avoid an incorrect warning with // Cfront-based compilers. const T& retval = a < b ? b : a; return retval; } template inline const T& min(const T& a, const T& b) { // Break this into two lines to avoid an incorrect warning with // Cfront-based compilers. const T& retval = b < a ? b : a; return retval; } #endif #ifndef CLHEP_SQR_DEFINED #define CLHEP_SQR_DEFINED #ifdef sqr #undef sqr #endif #ifndef HEP_SQR_NEEDS_PARAMETER_WITHOUT_CONST template inline T sqr(const T& x) { return x*x; } #else template inline T sqr(T x) { return x*x; } #endif /* HEP_SQR_NEEDS_PARAMETER_WITHOUT_CONST */ #endif #ifndef CLHEP_ABS_DEFINED #define CLHEP_ABS_DEFINED #ifdef abs #undef abs #endif #ifndef HEP_ABS_NEEDS_PARAMETER_WITHOUT_CONST template inline T abs(const T& a) { return a < 0 ? -a : a; } #else template inline T abs(T a) { return a < 0 ? -a : a; } #endif /* HEP_ABS_NEEDS_PARAMETER_WITHOUT_CONST */ #endif #endif /* HEP_TEMPLATEFUNCTIONS_H */