Boost logo

Boost :

From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-08-01 07:48:44


The boost::swap utility (svn/boost/trunk/boost/utility/swap.hpp) still
may call std::swap when the user has added a custom swap function to the
namespace of the user's type, because of some compiler bugs regarding
argument-dependent lookup (ADL). This issue will occur when using GCC
3.3.1, Intel C++ 8.1, MSVC 7.1, or Borland, as indicated by regression
failures of "specialized_in_global" and/or "specialized_in_other" for
those specific compilers:
http://www.boost.org/development/tests/trunk/developer/utility-swap_.html

Those compilers typically fail to do ADL within boost::swap's internal
helper function, boost_swap_impl::swap_impl<T>:

  template<class T>
  void swap_impl(T& left, T& right)
  {
    using std::swap;
    swap(left,right); // <-- Some compiles don't do ADL here!
  }

What about removing the the using-declaration, "using std::swap;", and
adding an extra function, boost_swap_impl::swap<T>? Which would
directly call std::swap, as follows:

  namespace boost_swap_impl
  {
    template<class T>
    void swap(T& left, T& right)
    {
      std::swap(left,right);
    }
  }

After doing so, MSVC 7.1 (2003) will pass both "specialized_in_global"
and "specialized_in_other", while it never did before. Borland will
pass "specialized_in_other" for the first time, as I tested locally on
BCC 5.8.4. Who knows, maybe it will also improve the regression results
of GCC 3.3.1 and Intel C++ 8.1... :-) Moreover, I think that such a
workaround could also be useful to other Boost libraries, when they
would start to use the boost::swap utility. For example, it could solve
some swap related regression failures of boost::optional.

What do you think? Would it be okay to commit this change to the trunk?

Hereby the patch I would like to apply.

Kind regards,

-- 
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center



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