Boost logo

Boost :

From: Matthew Towler (towler_at_[hidden])
Date: 2003-04-24 09:23:07


> Recently we tried to compile the boost 1.29 with some of our older Win32
> codes using the .NET 7.0
> compiler. We got an compiler error due to ambiguities of these overloads
> inside the CMap template
> implementation header <afxtempl.h>.

In VC6 the std::min and std::max templates were not present, so they are
often added manually (and probably in boost).

In VC7 these functions were put in the standard headers where they
should be, so any manually added versions cause problems. A tested
solution that will work across both is:

// MSVC does not have std::min and std::max unless using .NET (version 1300, VC++ 6 was version 1200)
#if _MSC_VER < 1300

namespace std
{

#ifdef min
#undef min
#endif

#ifdef max
#undef max
#endif

template <class T>
inline const T& min(const T& a, const T& b)
{
    return b < a ? b : a;
}

template <class T>
inline const T& max(const T& a, const T& b)
{
    return a < b ? b : a;
}

template <class T, class Compare>
inline const T& min(const T& a, const T& b, Compare comp)
{
    return comp(b, a) ? b : a;
}

template <class T, class Compare>
inline const T& max(const T& a, const T& b, Compare comp)
{
    return comp(a, b) ? b : a;
}

} // namespace std

#endif // _MSC_VER < 1300


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