Don't specialize std::swap, just overload it in the global namespace

This is the modern, correct way of providing a swap
operation. See http://stackoverflow.com/a/8439357/134841 for more
information. By changing this, we also fix Qt building with ICC
and libc++.

This patch also adds a noexcept() rule to match what the C++11 standard
requires.

Change-Id: I18f22fe7c92cf253e94168e1312346b4c183f536
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Thiago Macieira 2014-06-19 10:49:34 -07:00 committed by Marc Mutz
parent 3fc9f97d61
commit 62b67092ea

View File

@ -202,19 +202,14 @@ Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
types must define a member-swap, and be defined in the same
namespace as Qt for this to work.
*/
#define Q_DECLARE_SHARED_STL(TYPE) \
QT_END_NAMESPACE \
namespace std { \
template<> inline void swap< QT_PREPEND_NAMESPACE(TYPE) >(QT_PREPEND_NAMESPACE(TYPE) &value1, QT_PREPEND_NAMESPACE(TYPE) &value2) \
{ value1.swap(value2); } \
} \
QT_BEGIN_NAMESPACE
#define Q_DECLARE_SHARED(TYPE) \
Q_DECLARE_TYPEINFO(TYPE, Q_MOVABLE_TYPE); \
template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \
{ value1.swap(value2); } \
Q_DECLARE_SHARED_STL(TYPE)
inline void swap(TYPE &value1, TYPE &value2) \
Q_DECL_NOEXCEPT_EXPR(noexcept(value1.swap(value2))) \
{ value1.swap(value2); }
/*
QTypeInfo primitive specializations