Boost logo

Boost :

From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2004-02-24 02:45:49


Le mar 24/02/2004 à 02:58, Eric Niebler a écrit :
> John Maddock wrote:
> > Would you like to make and manage the change? Remove the workarounds from
> > win32.hpp, and then patch all occurrences of min and max throughout boost?
> >
> > John.
>
> <recap>
> We agreed to make boost work in the presence of the min/max macros by
> wrapping all min/max function identifiers in parens, like (std::min)(a,b);
> </recap>

Could you be a bit more precise about these modifications? I find this
"800" number quite huge. How did you deal with occurrences of min and
max that rely on ADL (sorry if that is not the correct term)? Or did you
handle only explicitly qualified calls std::min and std::max?

I'm asking because the Interval library relies on this kind of construct
in order to deal with built-in types (like int, float, etc) and
user-defined types (their min and max are found by Koenig lookup). I
know David Abrahams was recently suggesting to redefine functions in
their original namespace; but in the meantime, it is still common
practice to disallow any user definition in the std namespace.

Here is a small example:

#include <algorithm> // defines std::min

template< class T >
void f(T const &a, T const &b) {
  using std::min; min(a,b);
}

namespace n {
  struct c {};
  void min(c const &a, c const &b) { throw; }
}

int main() {
  n::c a;
  f(0, 0); // should call std::min
  f(a, a); // should call n::min
}

This code compiles as expected. However, if you replace "min" by "(min)"
and use GCC 3.4, it doesn't work anymore: f(a,a) will try to use
std::min. It seems to me that GCC 3.4 behaves accordingly to the
standard and that the second version of min can't be found if min is
wrapped in parentheses. So, which modification did you use in this case?

Sorry for the noise if the answer is trivial or if you didn't modify
this kind of construct.

Regards,

Guillaume

> I have spent some time and made the 800 or so edits throughout boost
> required to make it play nice with the min/max macros. I'm running
> regressions now. I have a couple of questions about procedure before I
> can commit the changes.
>
> 1) Is this a good time? I know there's talk about a 1.31.1 release. Will
> this be done from the 1.31.0 branch or from main? I don't want to
> destabilize before a release.
>
> 2) I can't test with old compilers, which are the ones most likely to
> have a hard time with this change. Also, I'm not a CVS guru. If all hell
> breaks loose as a result of this change, is there someone willing to
> help me back it out?
>
> 3) Is there a boost developer style guide where we can document the fact
> that all calls to min/max functions must be wrapped in parens?
>
> 4) This is the sort of thing developers will forget to do even if it's
> in a style guide. A simple way of ensuring this stays fixed would be to
> run the regressions with min() and max() #defined to garbage, so that
> violations are detected and corrected early. Is this possible?
>
> Thanks.


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