Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2004-02-24 12:14:35

David Abrahams wrote:

> They all compile and run the following:
> namespace std {
> template<class T> const T& min(const T& a, const T& b) { return a<b?a:b; }
> }
> int main()
> {
> int x = 0;
> int y = 1;
> return (std::min)(x,y);
> }
> But where will the definition of min come from on broken stdlib
> implementations?

Changing a call from min(a,b) to (min)(a,b) would break on stdlib
implementations that *only* have the min/max macros and not the min/max
algorithms, is that what you're saying? Do such implementations exist?
We'll have to provide the min/max algorithms for such platforms, I
suppose. Which platforms are affected?

>> 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?
> Just "cvs tag" to mark the state before you start making changes and
> it'll be comparitively easy.

Guess I should have done that before the 800 edits, huh? Hmm ...

>>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?
> Yes, it's possible, but that'll only detect the usage:
> min(x,y)
> and not
> std::min(x,y)
> both of which are going to be banned, right?

Why would it not detect the second? If I #define min(a,b) to garbage,
then the above becomes:


Mission accomplished.

Eric Niebler
Boost Consulting

Boost list run by bdawes at, gregod at, cpdaniel at, john at