Boost logo

Boost :

Subject: Re: [boost] [swap] please update documentation...
From: Dmitry Goncharov (dgoncharov_at_[hidden])
Date: 2009-06-30 04:36:09


Niels Dekker - address until 2010-10-10 wrote:
> 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 http://codepad.org/0lyaPrym
> Kind regards, Niels
>
Any of gcc-4.4.0, gcc-4.3.4 or gcc-4.2.4 compiles this program.
BR, Dmitry


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