summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-07-19 10:37:49 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-07-19 18:09:27 +0000
commit4ea3c0ba80e55e93ed0e03650325a046a676f73d (patch)
tree821771a7558aa210e2123e46a640677c755297c1 /tests/auto/corelib
parent8d1d12a32896cca3f9aaae31ae2a3ee28dc8f276 (diff)
QVector: add an rvalue overload of push_back/append
This is low-hanging fruit, for two reasons: 1. The implementation is dead-simple (unlike, say, in QList). 2. It's completely transparent to the QVector user (unlike, say, emplace_back, which can only be used inside an ifdef). Change-Id: Iaf750100cf61ced77aa452f0e4e3c4ec36b29639 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/qvector/qvector.pro1
-rw-r--r--tests/auto/corelib/tools/qvector/tst_qvector.cpp16
2 files changed, 17 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qvector/qvector.pro b/tests/auto/corelib/tools/qvector/qvector.pro
index 22edde3412..c1e0564915 100644
--- a/tests/auto/corelib/tools/qvector/qvector.pro
+++ b/tests/auto/corelib/tools/qvector/qvector.pro
@@ -1,4 +1,5 @@
CONFIG += testcase parallel_test
+contains(QT_CONFIG, c++11):CONFIG += c++11
TARGET = tst_qvector
QT = core testlib
SOURCES = $$PWD/tst_qvector.cpp
diff --git a/tests/auto/corelib/tools/qvector/tst_qvector.cpp b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
index e6f008d623..87822bca6f 100644
--- a/tests/auto/corelib/tools/qvector/tst_qvector.cpp
+++ b/tests/auto/corelib/tools/qvector/tst_qvector.cpp
@@ -190,6 +190,7 @@ private slots:
void appendInt() const;
void appendMovable() const;
void appendCustom() const;
+ void appendRvalue() const;
void at() const;
void capacityInt() const;
void capacityMovable() const;
@@ -638,6 +639,21 @@ void tst_QVector::appendCustom() const
QCOMPARE(instancesCount, Custom::counter.loadAcquire());
}
+void tst_QVector::appendRvalue() const
+{
+#ifdef Q_COMPILER_RVALUE_REFS
+ QVector<QString> v;
+ v.append("hello");
+ QString world = "world";
+ v.append(std::move(world));
+ QVERIFY(world.isEmpty());
+ QCOMPARE(v.front(), QString("hello"));
+ QCOMPARE(v.back(), QString("world"));
+#else
+ QSKIP("This test requires that C++11 move semantics support is enabled in the compiler");
+#endif
+}
+
void tst_QVector::at() const
{
QVector<QString> myvec;