
Hi Niels, I hope you don't mind me interjecting. We use the stlport std library with gcc 4.4.0 so I thought I'd add info about that to the thread. Niels Dekker wrote on 29/06/2009 18:33:18:
Re: [boost] [swap] please update documentation...
I'm very surprised it doesn't pick std::swap, as found by argument-dependent lookup. What version of GCC are you using exactly?
Peter Simons wrote:
The test program was compiled with g++ 4.4.0 20090526 (prerelease) on ArchLinux/x86.
Thanks Peter! It looks like a brandnew GCC bug to me... Can you please
confirm that the following simplified version also compiles and runs on your installation of GCC 4.4.0? And if so, does it indeed throw "foo::swap is called"?
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. #---------- GCC 4.4.0 + STLport 5.1.3 ------------ g++ swap.cpp swap.cpp:19: instantiated from here .../STLport-5.1.3-native/stlport/stl/_algobase.h:93: error: invalid array assignment #---------- GCC 4.4.0 + libstdc++ 4.4.0 ----------- CPLUS_INCLUDE_PATH= g++ swap.cpp ./a.out # no exception is thrown -- it's picking std::swap #---------- GCC 4.2.3 + libstdc++ 4.2.3 ------------ CPLUS_INCLUDE_PATH= g++-4.2.3 swap.cpp swap.cpp:19: instantiated from here ../include/c++/4.2.3/bits/stl_algobase.h:100: error: invalid array assignment #---------- GCC 4.4.0 + libstdc++ 4.4.0 ----------- The following compiles fine with 4.4.0 std library. Switch to stlport headers and it fails to compile as expected. CPLUS_INCLUDE_PATH= g++ -xc++ - << EOF #include <string> #include <algorithm> int main() { std::string a[42], b[42]; std::swap(a, b); } EOF #---------------------------------------- Does the C++0x library allow for std::swap with c-style arrays? If so, maybe the issue is that g++ is implementing it without needing you to specify --std=c++0x. I guess it is not breaking any existing use of std::swap -- just making a missing case work (?) Just to check that it actually is swapping I changed the body of the last snippet to: std::string a[42] = { "a", }, b[42] = { "b", }; std::swap(a, b); return a[0][0] - 'a'; and it did indeed swap. The return code was 1, not 0 -- so the first string in 'a' after the swap began with char 'b'. Hope this info's useful. Regards Adam ------------------------------------------------------------ This email and any attached files contains company confidential information which may be legally privileged. It is intended only for the person(s) or entity to which it is addressed and solely for the purposes set forth therein. If you are not the intended recipient or have received this email in error please notify the sender by return, delete it from your system and destroy any local copies. It is strictly forbidden to use the information in this email including any attachment or part thereof including copying, disclosing, distributing, amending or using for any other purpose. In addition the sender excludes all liabilities (whether tortious or common law) for damage or breach arising or related to this email including but not limited to viruses and libel. SELEX Communications Limited is a Private Limited Company registered in England and Wales under Company Number 964533 and whose Registered Office is Lambda House, Christopher Martin Rd, Basildon, SS14 3EL. England.