Make wxRound() compile for all integer types again

Replace the overloads added in c2e5f3520a (Add a wxRound() overload for
int, 2020-11-05) and 1cf7c47934 (Add more wxRound() compatibility
overloads and improve docs, 2020-11-05) with a template function that
should work for all integer types.

This fixes compilation of existing code using wxRound() with size_t
values: while this doesn't make any sense, it doesn't make much less
sense than using it with int, so let people avoid having to change their
code when upgrading to wx 3.2.

Also add at least some minimal tests for this function.

Closes https://github.com/wxWidgets/wxWidgets/pull/2119
This commit is contained in:
Vadim Zeitlin
2020-11-18 14:14:22 +01:00
parent 712c2d4004
commit a1d43c9363
2 changed files with 44 additions and 7 deletions

View File

@@ -158,3 +158,32 @@ TEST_CASE("wxCTZ", "[math]")
WX_ASSERT_FAILS_WITH_ASSERT( wxCTZ(0) );
}
TEST_CASE("wxRound", "[math]")
{
CHECK( wxRound(2.3) == 2 );
CHECK( wxRound(3.7) == 4 );
CHECK( wxRound(-0.5f) == -1 );
WX_ASSERT_FAILS_WITH_ASSERT( wxRound(2.0*INT_MAX) );
WX_ASSERT_FAILS_WITH_ASSERT( wxRound(1.1*INT_MIN) );
// For compatibility reasons, we allow using wxRound() with integer types
// as well, even if this doesn't really make sense/
#if WXWIN_COMPATIBILITY_3_0
#ifdef __VISUALC__
#pragma warning(push)
#pragma warning(disable:4996)
#endif
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
CHECK( wxRound(-9) == -9 );
CHECK( wxRound((size_t)17) == 17 );
CHECK( wxRound((short)289) == 289 );
wxGCC_WARNING_RESTORE(deprecated-declarations)
#ifdef __VISUALC__
#pragma warning(pop)
#endif
#endif // WXWIN_COMPATIBILITY_3_0
}