
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"? //////////////////////////////////////// #include <string> #include <algorithm> namespace foo { template<class T1, class T2> void swap(T1&, T2&) { throw "foo::swap is called"; } } int main() { std::string a1[42]; std::string a2[42]; using foo::swap; swap(a1, a2); } //////////////////////////////////////// So far, I've tried Comeau C/C++ 4.3.10.1 (online at www.comeaucomputing.com/tryitout), MSVC 2008 SP1, gcc-4 (GCC) 4.3.2 20080827 (beta) 2 within cygwin, and g++ 4.1.2 at http://codepad.org/76xnAQ7n None of them pick foo::swap. Instead, all of them yield a compile error, trying to call std::swap. Kind regards, Niels