Problems with std::min when I switched from 1.31 to 1.32

I just switched from boost 1.31 to 1.32 and now any code that uses std::min() or std::max() gives me this error with Visual Studio 2003: ReportResults.cpp(791) : error C2589: '(' : illegal token on right side of '::' ReportResults.cpp(791) : error C2059: syntax error : '::' I even tried something simple like this: int i = std::min(1, 2); And that fails as well. If I switch back to boost 1.31, no problems. I'm sure there must be a simple solution. Any help would be appreciated! Thanks, Scott

Scott Moore wrote:
I just switched from boost 1.31 to 1.32 and now any code that uses std::min() or std::max() gives me this error with Visual Studio 2003:
ReportResults.cpp(791) : error C2589: '(' : illegal token on right side of '::' ReportResults.cpp(791) : error C2059: syntax error : '::'
I even tried something simple like this:
int i = std::min(1, 2);
And that fails as well.
This is due to the min and max macros defined in
If I switch back to boost 1.31, no problems. I'm sure there must be a simple solution. Any help would be appreciated!
The Boost config header win32.hpp used to disable these but no longer does. You can disable the macros yourself by defining NOMINMAX before including Windows headers. Ben.

This is due to the min and max macros defined in
(or one of the headers it includes). If I switch back to boost 1.31, no problems. I'm sure there must be a simple solution. Any help would be appreciated!
The Boost config header win32.hpp used to disable these but no longer does. You can disable the macros yourself by defining NOMINMAX before including Windows headers.
Ben.
Thanks for the info. I looked thru some boost headers and noticed some code like: (std:min)(x, y) On a whim, I added this to my code and BINGO, everything compiles fine. I am curious why this fixed it though? Is it because the preprocessor mangled the "min" before the compiler saw it? And the parenthesis, in effect, prevent the preprocessor from expanding the macro? Thanks, Scott

cheesy4poofs wrote:
I looked thru some boost headers and noticed some code like: (std:min)(x, y)
On a whim, I added this to my code and BINGO, everything compiles fine. I am curious why this fixed it though? Is it because the preprocessor mangled the "min" before the compiler saw it?
Yup. And the parenthesis, in effect,
prevent the preprocessor from expanding the macro?
Yup. Function-like macros are only applied when the name of the macro is immediately followed by (optional whitespace and) an opening paren. When you say (std::min)(x, y), the min macro cannot apply because of the closing paren after "min". HTH, -- Eric Niebler Boost Consulting www.boost-consulting.com

At Wednesday 2005-01-19 11:12, you wrote:
Scott Moore wrote:
I just switched from boost 1.31 to 1.32 and now any code that uses std::min() or std::max() gives me this error with Visual Studio 2003: ReportResults.cpp(791) : error C2589: '(' : illegal token on right side of '::' ReportResults.cpp(791) : error C2059: syntax error : '::' I even tried something simple like this: int i = std::min(1, 2); And that fails as well.
This is due to the min and max macros defined in
(or one of the headers it includes). If I switch back to boost 1.31, no problems. I'm sure there must be a simple solution. Any help would be appreciated!
The Boost config header win32.hpp used to disable these but no longer does. You can disable the macros yourself by defining NOMINMAX before including Windows headers.
remind me of the logic behind requiring the user to now #define NOMINMAX
Ben. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"

Victor A. Wagner Jr. wrote:
At Wednesday 2005-01-19 11:12, you wrote:
The Boost config header win32.hpp used to disable these but no longer does. You can disable the macros yourself by defining NOMINMAX before including Windows headers.
remind me of the logic behind requiring the user to now #define NOMINMAX
The old win32.hpp unconditionally #undef'ed min and max. In their place, win32.hpp defined global min and max templates. However, these didn't behave quite the same way as the min and max macros. In some situations, the calls were ambiguous, and at other times, the behavior of some users' programs was silently changed. This is a Bad Thing. So we don't monkey with the min and max macros anymore. -- Eric Niebler Boost Consulting www.boost-consulting.com

At Wednesday 2005-01-19 12:24, you wrote:
Victor A. Wagner Jr. wrote:
At Wednesday 2005-01-19 11:12, you wrote:
The Boost config header win32.hpp used to disable these but no longer does. You can disable the macros yourself by defining NOMINMAX before including Windows headers.
remind me of the logic behind requiring the user to now #define NOMINMAX
The old win32.hpp unconditionally #undef'ed min and max. In their place, win32.hpp defined global min and max templates. However, these didn't behave quite the same way as the min and max macros. In some situations, the calls were ambiguous, and at other times, the behavior of some users' programs was silently changed. This is a Bad Thing. So we don't monkey with the min and max macros anymore.
tradition (#define max(a,b)......) is a wonderful thing, it just lasts too long.
-- Eric Niebler Boost Consulting www.boost-consulting.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Victor A. Wagner Jr. http://rudbek.com The five most dangerous words in the English language: "There oughta be a law"
participants (5)
-
Ben Hutchings
-
cheesy4poofs
-
Eric Niebler
-
Scott Moore
-
Victor A. Wagner Jr.