Remove qSwap specialization from Q_DECLARE_SHARED

The way swapping is supposed to work is:

1. Each type supplies a swap() function or function template in its
   namespace. Any good STL implementation will find it there through
   ADL. As will the primary qSwap() template.
2. Each use of swap() in Qt, in particular in template code, should
   use qSwap() instead of std::swap() or the using+swap-trick, because
   qSwap() automatically enables ADL. It also has a sophisticated
   conditional noexcept specification that can be used in the
   custom swap() functions' own noexcept clause.

This change also allows us to convert implicitly-shared classes'
member-swap functions to noexcept one at a time, because the
specialization will no longer be in conflict with the primary
template regarding exception specifications. The primary's
specification could, of course, be reused here, but it's complex
and if the machinery around it is changed later on, it will not
affect Q_DECLARE_SHARED classes.

Change-Id: I3389a655a9fd8de370f363c8fcef60269a9f506c
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2015-01-09 23:51:26 +01:00
parent a627c8628f
commit 676cb678cc

View File

@ -205,8 +205,6 @@ Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
#define Q_DECLARE_SHARED(TYPE) \
Q_DECLARE_TYPEINFO(TYPE, Q_MOVABLE_TYPE); \
template <> inline void qSwap<TYPE>(TYPE &value1, TYPE &value2) \
{ value1.swap(value2); } \
inline void swap(TYPE &value1, TYPE &value2) \
Q_DECL_NOEXCEPT_EXPR(noexcept(value1.swap(value2))) \
{ value1.swap(value2); }