From 958aaf377069368ce409db3f09a6ac3e38af7de2 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 25 Apr 2012 11:09:48 +0200 Subject: [PATCH] Add qMove macro to support std::move Change-Id: I373e07f479c11b172dab35ed7e5b62724aa50a1a Reviewed-by: Thiago Macieira --- src/corelib/global/qcompilerdetection.h | 6 ++++++ src/corelib/global/qglobal.cpp | 8 ++++++++ tests/auto/other/collections/tst_collections.cpp | 3 +++ 3 files changed, 17 insertions(+) diff --git a/src/corelib/global/qcompilerdetection.h b/src/corelib/global/qcompilerdetection.h index 8621d8b..68c8f73 100644 --- a/src/corelib/global/qcompilerdetection.h +++ b/src/corelib/global/qcompilerdetection.h @@ -779,4 +779,10 @@ # endif #endif +#ifdef Q_COMPILER_RVALUE_REFS +#define qMove(x) std::move(x) +#else +#define qMove(x) (x) +#endif + #endif // QCOMPILERDETECTION_H diff --git a/src/corelib/global/qglobal.cpp b/src/corelib/global/qglobal.cpp index 1bc02e0..9008591 100644 --- a/src/corelib/global/qglobal.cpp +++ b/src/corelib/global/qglobal.cpp @@ -3006,4 +3006,12 @@ bool QInternal::activateCallbacks(Callback cb, void **parameters) {Debugging Techniques} */ +/*! + \macro qMove(x) + \relates + + It expands to "std::move" if your compiler supports that C++11 function, or to nothing + otherwise. +*/ + QT_END_NAMESPACE diff --git a/tests/auto/other/collections/tst_collections.cpp b/tests/auto/other/collections/tst_collections.cpp index 26e3ccf..f9905ce 100644 --- a/tests/auto/other/collections/tst_collections.cpp +++ b/tests/auto/other/collections/tst_collections.cpp @@ -2556,6 +2556,9 @@ void testContainer() c1 = newInstance(); QVERIFY(c1.size() == 4); QVERIFY(c1 == newInstance()); + Container c2 = qMove(c1); + QVERIFY(c2.size() == 4); + QVERIFY(c2 == newInstance()); } } -- 2.7.4