[Development] QVector rvalue overloads for convenience functions?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Tue Mar 6 10:05:39 CET 2018


Il 06/03/2018 01:42, Kevin Kofler ha scritto:
> I would also like to point out that the actual gain of having an
> append(QVector<T> &&) over the current append(const QVector<T> &) would be
> very limited. At best you would save a pair of atomic integer operations.

No, because the former would move all elements.

template <typename T>
void QVector<T>::append(const QVector<T> &v)
{
     reserve(size() + v.size());
     std::copy(v.begin(), v.end(), std::back_inserter(this));
}

template <typename T>
void QVector<T>::append(QVector<T> &&v)
{
     reserve(size() + v.size());
     std::move(v.begin(), v.end(), std::back_inserter(this));
}

> All this complexity of rvalue references and std::move in C++11 and newer is
> only necessary because the STL containers are not implicitly shared.

Not at all, you may want to exactly the same for std::vector.

My 2 c,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4007 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180306/31c60261/attachment.bin>


More information about the Development mailing list