From 1cf7c4793430fb514d7aef141b449704438dcb3d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 5 Nov 2020 23:13:09 +0100 Subject: [PATCH] Add more wxRound() compatibility overloads and improve docs Make the overloads added for compatibility available only when WXWIN_COMPATIBILITY_3_0 is on and add two more of them, to cover all the interer types (except char but, honestly, who rounds those?). Also improve the documentation and make it clear that this function is not needed at all in the new code. Closes https://github.com/wxWidgets/wxWidgets/pull/2111 --- include/wx/math.h | 12 ++++++++++++ interface/wx/math.h | 13 +++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/wx/math.h b/include/wx/math.h index a9cc8df6df..3ae886cc35 100644 --- a/include/wx/math.h +++ b/include/wx/math.h @@ -164,9 +164,21 @@ inline int wxRound(float x) inline int wxRound(long double x) { return wxRound(double(x)); } +// For compatibility purposes, define wxRound() overloads for integer types +// too, as this used to compile with wx 3.0. +#if WXWIN_COMPATIBILITY_3_0 + wxDEPRECATED_MSG("rounding an integer is useless") inline int wxRound(int x) { return x; } +wxDEPRECATED_MSG("rounding an integer is useless") +inline int wxRound(short x) { return x; } + +wxDEPRECATED_MSG("rounding an integer is useless") +inline int wxRound(long x) { return static_cast(x); } + +#endif // WXWIN_COMPATIBILITY_3_0 + // Convert between degrees and radians. inline double wxDegToRad(double deg) { return (deg * M_PI) / 180.0; } inline double wxRadToDeg(double rad) { return (rad * 180.0) / M_PI; } diff --git a/interface/wx/math.h b/interface/wx/math.h index 5774680131..5e0b6e3d2c 100644 --- a/interface/wx/math.h +++ b/interface/wx/math.h @@ -89,9 +89,18 @@ double wxRadToDeg(double rad); unsigned int wxCTZ(wxUint32 x); /** - Small wrapper around round(). + Small wrapper around std::lround(). + + This function exists for compatibility, as it was more convenient than + std::round() before C++11. Use std::lround() in the new code. + + It is defined for all floating point types @c T and can be also used with + integer types for compatibility, but such use is deprecated -- simply + remove the calls to wxRound() from your code if you're using it with + integer types, it is unnecessary in this case. */ -int wxRound(double x); +template +int wxRound(T x); /** Returns true if both double values are identical. This is