Make wxMin, wxMax and wxClip template functions.

Previously used macro's arguments were evaluated twice, but there were
many occurences of their use in our code that didn't account for this
and used expensive-to-evaluate arguments as if they were functions.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65920 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2010-10-25 09:43:00 +00:00
parent 1f4c7e791b
commit a52475807e
3 changed files with 130 additions and 4 deletions

View File

@@ -20,6 +20,7 @@
#include "wx/list.h"
#include "wx/filefn.h"
#include "wx/hashmap.h"
#include "wx/meta/implicitconversion.h"
#if wxUSE_GUI
#include "wx/gdicmn.h"
@@ -55,12 +56,33 @@ class WXDLLIMPEXP_FWD_CORE wxWindow;
class WXDLLIMPEXP_FWD_CORE wxWindowList;
// ----------------------------------------------------------------------------
// Macros
// Arithmetic functions
// ----------------------------------------------------------------------------
#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)
{
return (a > b) ? a : b;
}
template<typename T1, typename T2>
inline typename wxImplicitConversionType<T1,T2>::value
wxMin(T1 a, T2 b)
{
return (a < b) ? a : b;
}
template<typename T1, typename T2, typename T3>
inline typename wxImplicitConversionType3<T1,T2,T3>::value
wxClip(T1 a, T2 b, T3 c)
{
return (a < b) ? b : ((a > c) ? c : a);
}
// ----------------------------------------------------------------------------
// wxMemorySize
// ----------------------------------------------------------------------------
// wxGetFreeMemory can return huge amount of memory on 32-bit platforms as well
// so to always use long long for its result type on all platforms which