-#define wxMax(a,b) (((a) > (b)) ? (a) : (b))
-#define wxMin(a,b) (((a) < (b)) ? (a) : (b))
-#define wxClip(a,b,c) (((a) < (b)) ? (b) : (((a) > (c)) ? (c) : (a)))
+template<typename T1, typename T2>
+inline typename wxImplicitConversionType<T1,T2>::value
+wxMax(T1 a, T2 b)
+{
+ typedef typename wxImplicitConversionType<T1,T2>::value ResultType;
+
+ // Cast both operands to the same type before comparing them to avoid
+ // warnings about signed/unsigned comparisons from some compilers:
+ return static_cast<ResultType>(a) > static_cast<ResultType>(b) ? a : b;
+}
+
+template<typename T1, typename T2>
+inline typename wxImplicitConversionType<T1,T2>::value
+wxMin(T1 a, T2 b)
+{
+ typedef typename wxImplicitConversionType<T1,T2>::value ResultType;
+
+ return static_cast<ResultType>(a) < static_cast<ResultType>(b) ? a : b;
+}
+
+template<typename T1, typename T2, typename T3>
+inline typename wxImplicitConversionType3<T1,T2,T3>::value
+wxClip(T1 a, T2 b, T3 c)
+{
+ typedef typename wxImplicitConversionType3<T1,T2,T3>::value ResultType;
+
+ if ( static_cast<ResultType>(a) < static_cast<ResultType>(b) )
+ return b;
+
+ if ( static_cast<ResultType>(a) > static_cast<ResultType>(c) )
+ return c;
+
+ return a;
+}
+
+// ----------------------------------------------------------------------------
+// wxMemorySize
+// ----------------------------------------------------------------------------