diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-07-19 10:37:49 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-07-19 18:09:27 +0000 |
commit | 4ea3c0ba80e55e93ed0e03650325a046a676f73d (patch) | |
tree | 821771a7558aa210e2123e46a640677c755297c1 /src/corelib/doc | |
parent | 8d1d12a32896cca3f9aaae31ae2a3ee28dc8f276 (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 'src/corelib/doc')
-rw-r--r-- | src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp index 77b34c95fc..5def361b83 100644 --- a/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_tools_qvector.cpp @@ -84,14 +84,27 @@ for (int i = 0; i < 10; ++i) //! [7] -QVector<QString> vector(0); +QVector<QString> vector; vector.append("one"); vector.append("two"); -vector.append("three"); +QString three = "three"; +vector.append(three); // vector: ["one", "two", "three"] +// three: "three" //! [7] +//! [move-append] +QVector<QString> vector; +vector.append("one"); +vector.append("two"); +QString three = "three"; +vector.append(std::move(three)); +// vector: ["one", "two", "three"] +// three: "" +//! [move-append] + + //! [8] QVector<QString> vector; vector.prepend("one"); |