Solution to Windows' min/max problem?

I learned some new stuff from another post about the min/max macros given in the Windows headers. Can the following suppositions and solution work? 1. The MS Windows headers define "min" and "max" macros 2. But nothing in those headers _actually needs_ those macros 3. These macros prevent STL from working 4. A "NOMINMAX" #define can be created to turn off the macros 5. Using the #define will fix STL _without_ breaking the MS stuff 6. The #define would break user code that uses the macros, though 7. If an user with that breakage includes STL, they have an alternate "min" and "max" available! 8. Boost pretty much requires STL So why can't we add: #if defined(min) || defined(max) #error Define NOMINMAX and use the alternates in <algorithm> #endif -- Daryle Walker Mac, Internet, and Video Game Junkie darylew AT hotmail DOT com

Daryle Walker wrote:
1. The MS Windows headers define "min" and "max" macros 2. But nothing in those headers _actually needs_ those macros
Try this with VC7.1: #define NOMINMAX #include <afxtempl.h> int main() { CArray<int> array; array.SetSize(3); return 0; } f:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\atlmfc\include\afxtempl.h(398): error C3861: 'max': identifier not found, even with argument-dependent lookup Regretably, there *is* code out there that require the min/max macros, even platform headers.
So why can't we add:
#if defined(min) || defined(max) #error Define NOMINMAX and use the alternates in <algorithm> #endif
Because this will break people's code in a way they can't easily fix. Nor should they have to. -- Eric Niebler Boost Consulting www.boost-consulting.com

"Eric Niebler" <eric@boost-consulting.com> writes:
So why can't we add: #if defined(min) || defined(max) #error Define NOMINMAX and use the alternates in <algorithm> #endif
Because this will break people's code in a way they can't easily fix. Nor should they have to.
Actually, not. It would be ineffectual, because NOMINMAX only matters before min and max are #defined. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (3)
-
Daryle Walker
-
David Abrahams
-
Eric Niebler