summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2021-08-12 12:13:15 +0200
committerMarc Mutz <marc.mutz@kdab.com>2021-08-16 17:26:29 +0000
commit29cfea3e82e04345b2cbb07c3ebebebbe3ced0bb (patch)
treeb785d7a186ac37f30b10d4c634a802047ea60a93 /tests/auto/corelib/tools
parente7ab88870041a862a44e2779198f808047973d5f (diff)
QVarLengthArray: add support for emplacement
Take the rvalue insert() function and turn it into the emplace() function. Reformulate rvalue-insert using emplace(). Lvalue insert() is using a different code path, so leave that alone. This way, we don't need to go overboard with testing. [ChangeLog][QtCore][QVarLengthArray] Added emplace(), emplace_back(). Change-Id: I3e1400820ae0dd1fe87fd4b4c518f7f40be39f8b Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r--tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
index 4dd8cbf8ba..0598a39cb6 100644
--- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
+++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp
@@ -70,6 +70,7 @@ class tst_QVarLengthArray : public QObject
private slots:
void append();
void prepend();
+ void emplace();
void move_int_1() { move_int<1>(); }
void move_int_2() { move_int<2>(); }
void move_int_3() { move_int<3>(); }
@@ -164,6 +165,24 @@ void tst_QVarLengthArray::prepend()
QCOMPARE(v.front(), v.back());
}
+void tst_QVarLengthArray::emplace()
+{
+ {
+ QVarLengthArray<QString, 2> strings;
+ strings.emplace_back();
+ QCOMPARE(strings.size(), 1);
+ QCOMPARE(strings.front().isNull(), true);
+ strings.emplace(strings.begin(), 42, u'x');
+ QCOMPARE(strings.size(), 2);
+ QCOMPARE(strings.back().isNull(), true);
+ QCOMPARE(strings.front(), QString(42, u'x'));
+ auto &r = strings.emplace_back(42, u'y');
+ QCOMPARE(&r, &strings.back());
+ QCOMPARE(strings.size(), 3);
+ QCOMPARE(strings.back(), QString(42, u'y'));
+ }
+}
+
template <qsizetype N>
void tst_QVarLengthArray::move_Tracker()
{