Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-07-05 14:48:56


> Another reasonable approach is to go ahead and implement the work-around,
> and document that code expecting the macros may need to be modified. In
> most cases, this will work just fine and so can amount the less total
> effort than the about 3 options. Plus it has the side benefit that the
> user will have a working min/max, which the user may want anyway, even if
> he doesn't want STLport. However, due to the potential for problems,
> even if rare, I would recommend putting the fix into a separate header
> that is only included by the boost libraries that need it, rather than
> bundling this fix into config.hpp.

Thanks for your thoughts Ed.

OK then, what do you think of a boost/algorithm.hpp that looks something
like this:

#ifndef BOOST_ALGORITHM_HPP
#define BOOST_ALGORITHM_HPP

// Boost algorithm.hpp header file
//
// (C) Copyright Mark Rodgers 2000. Permission to copy, use, modify, sell
// and distribute this software is granted provided this copyright notice
// appears in all copies. This software is provided "as is" without
// express or implied warranty, and with no claim as to its suitability
// for any purpose.
//
// See http://www.boost.org for the most recent version.
//
// Wrapper for the standard <algorithm> header. Includes that header
// and then applies any compiler-specific fixes required to make the
// implementation more conforming.
#include <algorithm>
#include <boost/config.hpp>

#if defined(BOOST_MSVC) && _MSC_VER <= 1200 && !defined(NOMINMAX)
// Visual C++ does not provide std::min and std::max because they are
// defined as macros in windef.h. If NOMINMAX is defined, windef.h
// will not define them, so we define this to guard against future
// inclusion of windef.h. We also assume that if this is already
// defined, some other header (e.g. STLport's <algorithm>) has already
// supplied a similar fix, so don't do attempt our own.
# undef min
# undef max
# define NOMINMAX
namespace std
{
 template<class T> inline const T &max(const T &x, const T &y)
    { return x < y ? y : x; }
 template<class T> inline const T &min(const T &x, const T &y)
    { return y < x ? y : x; }
}
// Any code using the macros will not be using std::, so unfortunately
// we need to bring the fixed templates into the global namespace.
using std::min;
using std::max;
#endif

#endif // BOOST_ALGORITHM_HPP


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