Article ID: 143208
Article Last Modified on 8/3/2001
#ifndef NOMINMAX #ifndef max #define max(a,b) (((a) > (b)) ? (a) : (b)) #endif #ifndef min #define min(a,b) (((a) < (b)) ? (a) : (b)) #endif #endif /* NOMINMAX */NOTE: Windef.h is included by Windows.h, which is included in nearly every Windows-based program.
template <class T>
inline const T& min(const T& a, const T& b) {
return b < a ? 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>
inline const T& max(const T& a, const T& b) {
return a < b ? 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;
}
Because the Windef.h definition is a macro, the function definitions cause
syntax errors when both Windef.h (or Windows.h) and Algobase.h (from the
STL) are included. The precise errors will depend on the order in which the
two are compiled.
Keywords: kbprb kb3rdparty KB143208