This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [Patch] libstdc++/29989



On Dec 4, 2006, at 1:02 PM, Paolo Carlini wrote:


Doug Gregor wrote:

<windows.h> is known to #define min and max as macros.

Interesting, thanks. Then, what do you suggest? Should we undef min and max elsewhere too? The PR was about <limits>, which, at some point in the far past also had undefs, not anymore...

In Boost, we do backflips to avoid the problem without #undef'ing min or max. We have a macro like this:


#define BOOST_PREVENT_MACRO_SUBSTITUTION

To use min or max in the library, we write, e.g.,

min BOOST_PREVENT_MACRO_SUBSTITUTION (x, y)

min and max can then be defined in the library like this:

template <class _Tp>
inline const _Tp& min BOOST_PREVENT_MACRO_SUBSTITUTION (const _Tp& __a, const _Tp& __b) {
return __b < __a ? __b : __a;
}
template <class _Tp>
inline const _Tp& max BOOST_PREVENT_MACRO_SUBSTITUTION (const _Tp& __a, const _Tp& __b) {
return __a < __b ? __b : __a;
}


With this hack, we don't need to #undef min and max, because we can tolerate the macro versions. libstdc++ could jump through these same hoops, but I don't know if that's the right answer. <windows.h> is wrong to #define "min" and "max"... should libstdc++ correct that wrong, by #undef'ing them, or should it just deal with the problem and let users do the same?

	Cheers,
	Doug


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]