diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-01-07 15:45:15 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-01-08 00:39:50 +0100 |
commit | daaf3b8578294dfa5e51562739acc935a148fa60 (patch) | |
tree | 4a20f7649d3c5c7991a3d167004f48a55ffdf027 /src/corelib | |
parent | 597a71fa99ea4845d61e5db630de02d73bf37421 (diff) |
QPair: add member-swap
std::pair has it, too.
Change-Id: I2526b09455db5502ad38a81f3d401098d54614a5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qpair.h | 12 | ||||
-rw-r--r-- | src/corelib/tools/qpair.qdoc | 25 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/corelib/tools/qpair.h b/src/corelib/tools/qpair.h index ae33d598d4..a9f6525479 100644 --- a/src/corelib/tools/qpair.h +++ b/src/corelib/tools/qpair.h @@ -62,10 +62,22 @@ struct QPair { first = std::move(p.first); second = std::move(p.second); return *this; } #endif + Q_DECL_RELAXED_CONSTEXPR void swap(QPair &other) + Q_DECL_NOEXCEPT_EXPR(noexcept(qSwap(other.first, other.first)) && noexcept(qSwap(other.second, other.second))) + { + // use qSwap() to pick up ADL swaps automatically: + qSwap(first, other.first); + qSwap(second, other.second); + } + T1 first; T2 second; }; +template <typename T1, typename T2> +void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) Q_DECL_NOEXCEPT_EXPR(noexcept(lhs.swap(rhs))) +{ lhs.swap(rhs); } + // mark QPair<T1,T2> as complex/movable/primitive depending on the // typeinfos of the constituents: template<class T1, class T2> diff --git a/src/corelib/tools/qpair.qdoc b/src/corelib/tools/qpair.qdoc index be329a0df0..f7b3c05db0 100644 --- a/src/corelib/tools/qpair.qdoc +++ b/src/corelib/tools/qpair.qdoc @@ -116,6 +116,31 @@ \sa qMakePair() */ +/*! + \fn void QPair::swap(QPair &other) + \since 5.5 + + Swaps this pair with \a other. + + Equivalent to + \code + qSwap(this->first, other.first); + qSwap(this->second, other.second); + \endcode + + Swap overloads are found in namespace \c std as well as via + argument-dependent lookup (ADL) in \c{T}'s namespace. +*/ + +/*! + \fn void swap(QPair<T1, T2> &lhs, QPair<T1, T2> &rhs) + \overload + \relates QPair + \since 5.5 + + Swaps \a lhs with \a rhs. +*/ + /*! \fn bool operator==(const QPair<T1, T2> &p1, const QPair<T1, T2> &p2) \relates QPair |