Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2008-07-26 14:30:59

on Sat Jul 26 2008, Niels Dekker - mail address until 2008-12-31 <> wrote:

> Steven Watanabe wrote:
>> Adding overloads to namespace boost is not guaranteed to work either.
>> template<class T>
>> void foo(T& t1, T&t2) {
>> boost::swap(t1, t2);
>> }
>> class X {};
>> namespace boost {
>> void swap(X&, X&); // not found by foo.
>> }
> Thanks, Steven! So the user should make sure that all of her custom
> boost swap overloads are declared, /before/ including any function that
> actually calls boost::swap... right?

That is effectively impossible in practice. Someone else who is using
boost::swap may #include it earlier.

> class X; // forward declaration.
> namespace boost {
> void swap(X&, X&); // forward declaration.
> }
> template<class T>
> void foo(T& t1, T&t2) {
> boost::swap(t1, t2); // should find swap(X&, X&), right?
> }
> class X {};
> David Abrahams wrote:
>> Niels is talking about compilers with bugs, though. I don't know
>> if this would be a possible workaround for any of those compilers
>> or not, but several compilers do all name lookup in phase 2 so
>> this stands a chance of working.
> We could add more unit tests, to see if it would work for those specific
> compilers. But only if we'd agree that there's no objection against
> having end-users adding their overloads to the boost namespace... I
> tend to think that it's "morally right" to have the end-user provide
> template specializations of boost function templates, but I'm not sure
> about overloads... what do you think?

It's probably not a good idea, but as far as I'm concerned, when
compilers are broken, you can do all kinds of evil things to compensate
without getting sent to Heck.

>>> ADL failures appear to occur for GCC 3.3.1 (PathScale), Intel C++ 8.1,
>>> MSVC 7.1 (2003), and Borland (up to 5.9.3).
>> I just looked into some of these; it doesn't look like you need to do
>> anything for msvc-7.1 and gcc-3.1.1 other than to place your class in a
>> namespace other than the global one.
> gcc-3.1.1 can indeed find the custom swap by ADL when the user's class
> is in her own namespace (other than the global one). As you see,
> "specialized_in_other" succeeds for gcc-3.1.1. Unfortunately this is
> not the case for msvc-7.1: msvc-7.1 fails on both
> "specialized_in_global" and "specialized_in_other".

I could have sworn that's not what I saw when I responded to your
message, but it appears to be the case now. Also it really surprises me
because I know msvc-7.1 does do ADL.

> It just doesn't seem to do ADL on template arguments. :-(

I'm sorry, I'm not seeing how that is relevant to any of the failing
tests. What am I missing?

Dave Abrahams
BoostPro Computing

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