Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2004-01-02 13:01:41


John Maddock wrote:
>>Does adding:
>> #include <algorithm>
>
> Yes.

No. I'm including 2 programs, one for which including <algorithm> does
*not* remove the ambiguity, and one for which the inclusion of win32.hpp
silently changes the meaning of the program. This fooling with the
min/max macros simply has to go.

//
// inclusion of win32.hpp silently changes the meaning of a program
//
#include <iostream>
using std::cout;
using std::endl;

#include <windows.h>

void foo()
{
     unsigned long i = 1;
     signed long j = -1;
     cout << max(i,j) << endl;
     cout << typeid(max(i,j)).name() << endl;
     cout << endl;
}

#include <algorithm>
#include <boost/utility.hpp>

void bar()
{
     unsigned long i = 1;
     signed long j = -1;
     cout << max(i,j) << endl;
     cout << typeid(max(i,j)).name() << endl;
     cout << endl;
}

int main()
{
     foo();
     bar();
     return 0;
}

Output:

4294967295
unsigned long

1
long

//
// win32.hpp makes a call to max ambiguous
//
#include <algorithm>
#include <boost/utility.hpp>

int main()
{
     unsigned int i = 1;
     signed int j = -1;
     max(i,j);
     return 0;
}

f:\src\scratch_vc7\main.cpp(24): error C2668: 'std::max' : ambiguous
call to overloaded function

-- 
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