ikalnytskyi/termcolor

#define min() and #define max() pollute global namespace by including termcolor.hpp

trailfrenzy opened this issue · 4 comments

My work around was to #undef min and #undef max immediately after including termcolor.hpp. The macro version of min and max smashed the std::limits<>::min and std::limits<>::max. Is it possible to #undefine these two macros in termcolor.hpp since the min and max in now defined in #include which is the preferred way of using min() and max() for modern C++.

Same issue here with std::limits,
#undef min
#undef max
solved it

@trailfrenzy @jk-cx thanks for reporting that. Can you please confirm this issue is Windows specific?

If so, can you please try to compile your projects with NOMINMAX flag set (or #define NOMINMAX on the very first line in main.cpp)? Trying to do any hardcoded #undef-s inside termcolor may introduce the opposite side effect. I'd prefer not to do so. If that helps, I'll mention this caveat in README.

@ikalnytskyi Can confirm the code compiles with #define NOMINMAX. Turns out this seems to be a common problem on Windows and is introduced by windows.h, see here: https://stackoverflow.com/questions/11544073/how-do-i-deal-with-the-max-macro-in-windows-h-colliding-with-max-in-std. Would be nice if you could mention it somewhere, other than that I think you are right, if you add the define it could lead to problems in some projects using the library

Added this caveat to README.

fab28c5