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-02 07:51:10


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

Steven Watanabe wrote:
> There's a config macro |BOOST_FUNCTION_SCOPE_USING_DECLARATION_BREAKS_ADL|

Thanks! Interestingly, the macro is not defined for MSVC 7.1. And I'm
not sure if it should, because for MSVC 7.1, a function scope
using-declaration doesn't /always/ break ADL. But it definitely breaks
ADL within the current boost_swap_impl::swap_impl<T> function.

> Does it help to
> a) using namespace std;
> or
> b) put the using in the namespace rather than in the function

Yes it does!!! :-) Workaround "a" does the job! I tested locally, for
msvc-9.0, msvc-7.1, and borland-5.82.

Current SVN version of boost::swap:
 - msvc-9.0 passes all tests
 - msvc-7.1 fails on specialized_in_global, specialized_in_other
 - borland-5.82 fails on specialized_in_global, specialized_in_other,
and swap_arrays

Workaround a) "using namespace std;", instead of "using std::swap;",
within the boost_swap_impl::swap_impl<T> function:
 - msvc-9.0 passes all tests
 - msvc-7.1 passes all tests
 - borland-5.82 fails /only/ on swap_arrays

Workaround b) putting "using std::swap;" in the boost_swap_impl
namespace rather than in the boost_swap_impl::swap_impl<T> function:
 - msvc-9.0 passes all tests
 - msvc-7.1 passes all tests
 - borland-5.82 passes specialized_in_other, but it still fails on
specialized_in_global and swap_arrays.

Do you think it would be okay to just apply workaround "a", as attached
hereby? I mean, would it harm for other toolsets to have "using
namespace std;" within the boost_swap_impl::swap_impl function? I'd
rather not use BOOST_WORKAROUND (unless really necessary!), because it
would be harder to maintain, and I'd rather not have the semantics of
boost::swap differ from one compiler to another.

>> Anyway, I think we should add unit tests for std types!
> Definitely.

So I just added 7 tests, testing boost::swap on various types that have
std as associated namespace:

  std_bitset.cpp tests swapping std::bitset<T>.
  std_dateorder.cpp tests swapping the enum std::time_base::dateorder,
  std_string.cpp tests swapping std::string.
  std_typeinfo_ptr.cpp tests swapping typeinfo pointers.
  std_vector_of_boost.cpp tests swapping a vector of boost types.
  std_vector_of_global.cpp tests swapping a vector of types from the
global namespace.
  std_vector_of_other.cpp tests swapping a vector of types from another
namespace.

I think each of them /might/ independently fail, depending on compiler
bugs or (possibly) boost::swap utility bugs. The code is very much based
upon the original tests by Joseph. Please have a look:
http://svn.boost.org/trac/boost/changeset/47943

Kind regards,

  Niels



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