Boost logo

Boost :

From: Ed Brey (brey_at_[hidden])
Date: 2000-06-05 12:36:01


From: "Thomas Matelich" <sosedada_at_[hidden]>
> In MSVC 6, sp3, I'm getting an error in numeric_cast about the min
and max
> macro. Obviously, I need to undefine them, I was just wondering if
this is
> something that should be built into config.hpp somehow?

You're probably running into a problem with the MS headers (i.e.
windows.h) defining min and max as macros. This hoses up
std::numeric_limits and anything else that uses min and max as
members.

A workaround is to undefine min and max after you've included all the
windows headers. STLport provides a more elaborate workaround, which
is to undefine them and then define them as inline functions like MS
should do in windows.h in the first place.

In theory, we could put the appropriate detection and workaround in
boost's config.hpp, and although I can't think of where it would go
wrong, it just feels more intrusive and makes me a bit nervous for
such a widespread library as boost. There would have to be a good
deal of benefit to justify it.

The workaround would be like this, plus guards to check for MSVC and
to make sure that STLport isn't already doing the workaround for us:

#define NOMINMAX // Prevents subsequent macro definitions
#ifdef min
 #undef min
 #undef max
#endif
// Need to always define the inline functions, because of the NOMINMAX
definition.
template<class T> inline const T& min(const T& x, const T& y) {return
_cpp_min(x, y);}
template<class T> inline const T& max(const T& x, const T& y) {return
_cpp_max(x, y);}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk