Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2003-12-30 11:36:49


John Maddock wrote:

>>It seems extremely unwise to be undef'ing min and max. Evil though they
>>are, many Win32 platform headers (and users' headers!) depend on them,
>>and there is simply no way to write a template or set of overloads that
>>behave exactly as the macros do.
>
>
> I agree - but there is plenty of boost code that relies on std::min and
> std::max *not* being macros - were we not to do this then a fair portion of
> Boost would just stop working :-(

There are known ways of dealing with this problem. Putting parens around
the min and max identifiers prevents the macro invocation. For instance,

     std::max( a, b ); ==> (std::max)( a, b );

and

     struct foo { struct foo {
         int max(); ==> int (max)();
     }; };

It also turns off ADL, but I'd be surprised if any code in boost relies
on ADL with min/max.

> There is BTW a trivial fix for your problem: include the windows headers
> *before* any Boost ones.

This is not a trivial fix. I'm working on a project with ~30
sub-projects and over 5000 source files, with dozens of other
programmers making constant changes. Ensuring that no boost header gets
included before a windows/ATL/MFC header is a nightmare.

>
> However, there is also a bug in our workaround - we haven't include
> <algorithm> to get the template min/max functions as well as the additional
> overloads that we add in the workaround, and it's this that is the cause of
> the error in this case, I'm committing a revised win32.hpp which will now
> compile the sample you posted (or will be as soon as the config regression
> tests complete).

I described above how boost can be changed to accomodate the min/max
macros. Is there a reason why this approach is not used? Is there a
known issue with some compilers?

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk