summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-01-07 15:44:05 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-01-08 00:39:33 +0100
commit597a71fa99ea4845d61e5db630de02d73bf37421 (patch)
tree8c36bdf6f2fbb837573320a85729aa5fa0bd3a60 /src/corelib/global
parent0dacb1e2821b3e7a70e42babf64c0cc217a6fa5c (diff)
Make qSwap() noexcept, if possible
This greatly increases the value of qSwap(), since not only does it automatically do the parallel std+ADL lookup of swap(), but also now centralizes the rather messy code involved to create a correct noexcept specification. Other code now can simply use Q_DECL_NOEXCEPT_EXPT(noexcept(qSwap(lhs, rhs))). Change-Id: Ia35df4876b143e86c4150ac452a48c3775c3702b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qglobal.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h
index 273dcb9acb..48ba09075d 100644
--- a/src/corelib/global/qglobal.h
+++ b/src/corelib/global/qglobal.h
@@ -802,8 +802,20 @@ static inline bool qIsNull(float f)
# define Q_DUMMY_COMPARISON_OPERATOR(C)
#endif
+namespace QtPrivate
+{
+namespace SwapExceptionTester { // insulate users from the "using std::swap" below
+ using std::swap; // import std::swap
+ template <typename T>
+ void checkSwap(T &t)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(swap(t, t)));
+ // declared, but not implemented (only to be used in unevaluated contexts (noexcept operator))
+}
+} // namespace QtPrivate
+
template <typename T>
inline void qSwap(T &value1, T &value2)
+ Q_DECL_NOEXCEPT_EXPR(noexcept(QtPrivate::SwapExceptionTester::checkSwap(value1)))
{
using std::swap;
swap(value1, value2);