Boost logo

Boost :

From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-07-26 20:19:51


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

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

MSVC has a compiler option that has the effect of #include-ing a
specified header file on the first line of every source file (/FI, "Name
Forced Include File"). That header file could contain the declarations
of all user provided boost::swap overloads, when using MSVC 7.1... Ok,
it wouldn't be particularly elegant!

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

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

Okay, I'll see if I can add such a unit test tomorrow. It would
probably be based upon Joseph's "specialized_in_other" test, but having
an extra boost::swap overload declared and defined /after/ the #include
<boost/test/test_tools.hpp>. Hopefully that would be sufficient.

>> 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 surprised me as well, I only encountered this ADL bug very recently,
while I've been using msvc-7.1 for quite a while.

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

Here's where msvc-7.1 fails to do ADL, in utility/swap.hpp:

  template<class T>
  void swap_impl(T& left, T& right)
  {
    using std::swap;
    swap(left,right); // <-- No ADL by msvc-7.1
  }

While msvc-7.1 would have doing ADL if T would have been a specific
type, instead of a template argument.

Steven Watanabe wrote:
> msvc-7.1 is one of the compilers that does all look up in phase 2, I think.
> So...
>
> namespace users_namespace {
> class X {};
> void swap(X&, X&);
> }
>
> #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
> namespace boost {
> using users_namespace::swap;
> }
> #endif
>
> We have to use a #if to avoid an ODR violation for
> compilers that implement two-phase name lookup correctly.

So that would be an alternative workaround, to be used by end-users,
right? Instead of having them provide a boost::swap overload. (I guess
the #if should include GCC 3.3.1, Intel C++ 8.1, and Borland as well.)
Would it be preferable to adding a boost::swap overload?

  Good night, Niels


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