Talk:More C++ Idioms/Non-throwing swap

you shall *NOT* add specialization of swap in std, you shall provide overload in the type's namespace [27 May 2009]
 * True, although it's not illegal provided it's a specialization (as opposed to an overload), and even Sutter and Alexandrescu in their Coding Standards book (item 66) imply that this is a commonly adopted, acceptable solution if your compiler(s) don't support Koenig lookup. At least, that's my reading. 221.47.185.5 (talk) 03:27, 19 July 2009 (UTC)

This page is very wrong. Defining swap in both std and class namespace? Calling it a "common practice"? A link to comp.lang.c++.moderated discussion at the end of the page provides the correct solution, but it's completely ignored here. As it was already mentioned, you should provide an overload in the namespace of the class. When using swap, however, you shouldn't qualify it. You should do an unqualified call: 'using std::swap; swap(...);'. All compilers support ADL nowadays. It's not 1990ies any more.

I should add that for class templates it's not even possible to provide a swap specialization in the std namespace (no partial specializations for functions allowed). But if someone wants to do it as this page suggests, he'll end up with an overload. This overload will be illegal according to the Standard and it will interfere with swap specializations. Specializations do not overload - this language rule will put the ill-conceived swap overload ahead of properly written specializations in the overload resolution order. And it will likely result in some very strange compile-time error messages or runtime bugs.