How to call std::min() when min has been defined as a macro?

(std::min)(x,y)

The parentheses around min prevent macro expansion. This works with all function macros.


On Windows, you need to define NOMINMAX before including any windows headers, preferable at the beginning of precompiled header.


Use #undef min in your code, after #include <> directives.

#include <...> // bad header that defines `min` macro
#ifdef min
#undef min
#endif

// rest f code.

Addendum: If you need to keep the value of the min macro afterwards, you can disable its definition temporarily using a non-portable solution on some compilers. For instance, Microsoft's C++ compiler has a push_macro pragma that also seems to be supported by GCC.

Tags:

C++

Stl

Macros