Boost logo

Boost :

Subject: Re: [boost] [swap] please update documentation...
From: Niels Dekker - address until 2010-10-10 (niels_address_until_2010-10-10_at_[hidden])
Date: 2009-06-30 04:24:05

Adam Butcher wrote:
> I tried the above with gcc 4.4.0 and stlport. It chose std::swap
> (stlport's) via ADL and failed to compile due to 'invalid array
> assignment' as expected. It seems that the issue is with gcc 4.4.0's
> latest standard library rather than a broken ADL or other such detail.
> Looks like the latest gcc std::swap supports c-style array swapping.

Thanks very much.

Dmitry Goncharov wrote:
> You are right. bits/algorithmfwd.h contains
> template <typename _Tp, size_t _Nm>
> void
> swap(_Tp (&)[_Nm], _Tp (&)[_Nm]);

Cool! But still I'm concerned about the results from Peter Simons,
compiled with g++ 4.4.0 20090526 (prerelease). As that particular
version appears to pick boost::swap, instead of std::swap.

The implementation of boost::swap depends on compilers preferring
std::swap<T>(T&,T&) over boost::swap<T1,T2>(T1&,T2&), in case of an
unqualified swap function call. Thereby, ambiguity is avoided, as was
suggested by Steven Watanabe. I really hope this will still work on the
latest version of GCC.

Adam and Peter, could you please also test the following on g++ 4.4.0?
I really hope it compiles!


 namespace foo // "boost"
  template<class T1, class T2>
  void swap(T1&, T2&)
   // Trigger a compile error.
   int staticAssert[sizeof(T1)!=sizeof(T2)] = {1};

 namespace bar // "std"
  template<class T>
  void swap(T&, T&)
   return; // okay.

  class string {};

 int main()
  bar::string a1[42];
  bar::string a2[42];

  using foo::swap;
  swap(a1, a2);


At least, it does compile on g++ 4.1.2, at

Kind regards, Niels

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