Get rid of #define min/max in macros.h
The header src/gromacs/legacyheaders/macros.h #defines symbols min and max, which causes constant headache when compiling C++ source files. This is because quite a few standard C++ headers include <algorithm>, which defines these functions using templates. So if macros.h has been included before C++ headers, one quite often gets confusing error messages. Currently, I've worked around those by adding #undef statements in the source files (all should be marked with // FIXME), but a better solution should be found.
Fix name collision of min/max with C++ std::min/std::max
min/max is defined as the macro for C compililation and
as std::min/std::max for C++ compilation. New C++ code should not depend
on this so removed macros.h from other headers and added it where
needed. Removed hacks from existing C++ files where they were no longer
Fixes issue #806.
#1 Updated by Teemu Murtola almost 9 years ago
It actually seems that vec.h doesn't require macros.h, so the include statement could be simply removed from there. But several other headers quite likely include it as well, and some of them may actually need it. It also appears that quite a few files fail to compile if min/max are simply removed from macros.h. An #ifndef __cplusplus around them would break C++ compilation of C source files, so that is not ideal either. Nor is complementing it with #ifdef __cplusplus with alternative definitions, since there already exists std::min and std::max.
One solution that would not require larger changes to existing code could be to move the macros to a separate header, e.g., minmax.h. This header should not be included from any headers, but only from source files that actually need it. Also, it should not be used in new code, so that perhaps at some point it could be completely removed.
In the long run, quite a few of the definitions in macros.h don't seem to be very useful, so perhaps we should try to remove the whole header.
Some of the // FIXME hacks mentioned in the description are still in commits pending review in Gerrit, so it would be best to wait for them to do all the fixes at the same time.
#2 Updated by Teemu Murtola almost 9 years ago
I think that now all pending changes with those FIXME issues have been reviewed and merged, so this issue could be tackled as a whole.
I also noticed that source:src/gromacs/selection/params.cpp redefined max and min using templates, that should also be fixed to use std::min and std::max.