Hi there
Today I've noticed that all my appends to QVector create double copies of the data. So after inspection of the code I
found that not just append has the same issue, but replace and others too:
Source code of replace:
template <typename T>
inline void QVector<T>::replace(int i, const T &t)
{
Q_ASSERT_X(i >= 0 && i < d->size, "QVector<T>::replace", "index out of range");
const T copy(t);
data()[i] = copy;
}
Now can somebody please explain me why a local copy is made?
From my point of view:
1. we don't need a local copy in the first place
2. but if we had it, why is it defined as a 'const', so that even a move operation can't be called on the data??
Now I have to assume that author wanted to do something with this (maybe some compiler issues??), but I can't find the explanation.
Any insights?
Best regards
Waldemar
Bookmarks