From 95f6278e8277c08eee888c6c1ba2c58b74a346a7 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Thu, 26 Feb 2004 18:27:02 +0000 Subject: [PATCH] remove minmax hack from win32.hpp and fix all places that could be affected by the minmax macros [SVN r22394] --- include/boost/config.hpp | 3 ++ include/boost/config/platform/win32.hpp | 41 ------------------------- include/boost/detail/limits.hpp | 29 ++++++----------- test/limits_test.cpp | 20 ++++++------ 4 files changed, 23 insertions(+), 70 deletions(-) diff --git a/include/boost/config.hpp b/include/boost/config.hpp index 055a2785..e091e62b 100644 --- a/include/boost/config.hpp +++ b/include/boost/config.hpp @@ -53,6 +53,9 @@ # include BOOST_PLATFORM_CONFIG #endif +// used in various places to guard against the min/max macros +#define BOOST_PREVENT_MACRO_SUBSTITUTION + // get config suffix code: #include diff --git a/include/boost/config/platform/win32.hpp b/include/boost/config/platform/win32.hpp index a637dc37..ecdb395f 100644 --- a/include/boost/config/platform/win32.hpp +++ b/include/boost/config/platform/win32.hpp @@ -43,44 +43,3 @@ #endif -// -// disable min/max macros: -// -#ifdef min -# undef min -#endif -#ifdef max -# undef max -#endif -#ifndef NOMINMAX -# define NOMINMAX -#endif - -#ifdef BOOST_MSVC -#include // for existing std::min and std::max -namespace std{ - // Apparently, something in the Microsoft libraries requires the "long" - // overload, because it calls the min/max functions with arguments of - // slightly different type. (If this proves to be incorrect, this - // whole "BOOST_MSVC" section can be removed.) - inline long min(long __a, long __b) { - return __b < __a ? __b : __a; - } - inline long max(long __a, long __b) { - return __a < __b ? __b : __a; - } - // The "long double" overload is required, otherwise user code calling - // min/max for floating-point numbers will use the "long" overload. - // (SourceForge bug #495495) - inline long double min(long double __a, long double __b) { - return __b < __a ? __b : __a; - } - inline long double max(long double __a, long double __b) { - return __a < __b ? __b : __a; - } -} -using std::min; -using std::max; -# endif - - diff --git a/include/boost/detail/limits.hpp b/include/boost/detail/limits.hpp index 5f478e3e..03524403 100644 --- a/include/boost/detail/limits.hpp +++ b/include/boost/detail/limits.hpp @@ -94,23 +94,14 @@ enum float_denorm_style { static const __mem_type __mem_name = __mem_value #endif /* BOOST_NO_INCLASS_MEMBER_INITIALIZATION */ -// Deal with min/max for MinGW -#ifdef min -# undef min -#endif - -#ifdef max -# undef max -#endif - // Base class for all specializations of numeric_limits. template class _Numeric_limits_base { public: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, false); - static __number min() throw() { return __number(); } - static __number max() throw() { return __number(); } + static __number min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); } + static __number max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __number(); } BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, 0); BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits10, 0); @@ -164,8 +155,8 @@ class _Integer_limits : public _Numeric_limits_base<_Int> public: BOOST_STL_DECLARE_LIMITS_MEMBER(bool, is_specialized, true); - static _Int min() throw() { return __imin; } - static _Int max() throw() { return __imax; } + static _Int min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imin; } + static _Int max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return __imax; } BOOST_STL_DECLARE_LIMITS_MEMBER(int, digits, @@ -388,9 +379,9 @@ template<> class numeric_limits round_to_nearest> { public: - static float min() throw() { return FLT_MIN; } + static float min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MIN; } static float denorm_min() throw() { return FLT_MIN; } - static float max() throw() { return FLT_MAX; } + static float max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return FLT_MAX; } static float epsilon() throw() { return FLT_EPSILON; } static float round_error() throw() { return 0.5f; } // Units: ulps. }; @@ -416,9 +407,9 @@ template<> class numeric_limits round_to_nearest> { public: - static double min() throw() { return DBL_MIN; } + static double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MIN; } static double denorm_min() throw() { return DBL_MIN; } - static double max() throw() { return DBL_MAX; } + static double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return DBL_MAX; } static double epsilon() throw() { return DBL_EPSILON; } static double round_error() throw() { return 0.5; } // Units: ulps. }; @@ -444,9 +435,9 @@ template<> class numeric_limits round_to_nearest> { public: - static long double min() throw() { return LDBL_MIN; } + static long double min BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MIN; } static long double denorm_min() throw() { return LDBL_MIN; } - static long double max() throw() { return LDBL_MAX; } + static long double max BOOST_PREVENT_MACRO_SUBSTITUTION () throw() { return LDBL_MAX; } static long double epsilon() throw() { return LDBL_EPSILON; } static long double round_error() throw() { return 4; } // Units: ulps. }; diff --git a/test/limits_test.cpp b/test/limits_test.cpp index cc1bdfa4..56fd93b2 100644 --- a/test/limits_test.cpp +++ b/test/limits_test.cpp @@ -65,14 +65,14 @@ void test_integral_limits(const T &, const char * msg) typedef std::numeric_limits lim; std::cout << "Testing " << msg << " (size " << sizeof(T) << ")" - << " min: " << make_char_numeric_for_streaming(lim::min()) - << ", max: " << make_char_numeric_for_streaming(lim::max()) + << " min: " << make_char_numeric_for_streaming((lim::min)()) + << ", max: " << make_char_numeric_for_streaming((lim::max)()) << std::endl; BOOST_TEST(lim::is_specialized); BOOST_TEST(lim::is_integer); // BOOST_TEST(lim::is_modulo); - BOOST_TEST(lim::min() < lim::max()); + BOOST_TEST((lim::min)() < (lim::max)()); } template @@ -107,16 +107,16 @@ void test_float_limits(const T &, const char * msg) << ", traps: " << lim::traps << ", bounded: " << lim::is_bounded << ", exact: " << lim::is_exact << '\n' - << "min: " << lim::min() << ", max: " << lim::max() << '\n' + << "min: " << (lim::min)() << ", max: " << (lim::max)() << '\n' << "infinity: " << infinity << ", QNaN: " << qnan << '\n'; - print_hex_val(lim::max(), "max"); + print_hex_val((lim::max)(), "max"); print_hex_val(infinity, "infinity"); print_hex_val(qnan, "qnan"); print_hex_val(snan, "snan"); - BOOST_TEST(lim::max() > 1000); - BOOST_TEST(lim::min() > 0); - BOOST_TEST(lim::min() < 0.001); + BOOST_TEST((lim::max)() > 1000); + BOOST_TEST((lim::min)() > 0); + BOOST_TEST((lim::min)() < 0.001); BOOST_TEST(lim::epsilon() > 0); if(lim::is_iec559) { @@ -130,8 +130,8 @@ void test_float_limits(const T &, const char * msg) if(lim::has_infinity) { // Make sure those values are not 0 or similar nonsense. // Infinity must compare as if larger than the maximum representable value. - BOOST_TEST(infinity > lim::max()); - BOOST_TEST(-infinity < -lim::max()); + BOOST_TEST(infinity > (lim::max)()); + BOOST_TEST(-infinity < -(lim::max)()); } else { std::cout << "Does not have infinity" << std::endl; }