From c8af49d8884dccce346e929bbfb58e589aa93063 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 20 Aug 2002 22:56:13 +0000 Subject: [PATCH] Add templated min and max, which only evaluate their arguments once. (Switching to the STL will require this eventually, anyway.) Keep #defined MIN and MAX, for the few cases where we really do need compile-itme constants. Add min/max(float,int) and (int,float) specializations, since that's often used. --- stepmania/src/RageUtil.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 9c922a4b20..fbbce23096 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -26,14 +26,24 @@ inline int RECTCENTERX(RECT rect) { return rect.left + (rect.right-rect.left)/2; } inline int RECTCENTERY(RECT rect) { return rect.top + (rect.bottom-rect.top)/2; } -#ifndef max -#define max(a,b) (((a) > (b)) ? (a) : (b)) -#endif +#undef min +#undef max +#define NOMINMAX /* make sure Windows doesn't try to define this */ -#ifndef min -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#endif +template +inline const T & max(const T &a, const T &b) { return a > b? a:b; } +template +inline const T & min(const T &a, const T &b) { return a < b? a:b; } + +/* Common harmless mismatches. */ +inline float min(float a, int b) { return a < b? a:b; } +inline float max(float a, int b) { return a > b? a:b; } +inline float min(int a, float b) { return a < b? a:b; } +inline float max(int a, float b) { return a > b? a:b; } + +/* Traditional defines. Only use this if you absolutely need + * a constant value. */ #ifndef MAX #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif