Simplify {to,from}Std{List,Vector}

Use the newly-added range constructors.

Change-Id: I7f1d2699d88656fb7dddd11a9d781d810d45b0b4
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2019-02-10 18:43:05 +01:00 committed by Marc Mutz
parent b16fab1b63
commit b3c52e8224
2 changed files with 5 additions and 12 deletions

View File

@ -414,10 +414,10 @@ public:
Q_DECL_DEPRECATED_X("Use QList<T>(list.begin(), list.end()) instead.")
static inline QList<T> fromStdList(const std::list<T> &list)
{ QList<T> tmp; std::copy(list.begin(), list.end(), std::back_inserter(tmp)); return tmp; }
{ return QList<T>(list.begin(), list.end()); }
Q_DECL_DEPRECATED_X("Use std::list<T>(list.begin(), list.end()) instead.")
inline std::list<T> toStdList() const
{ std::list<T> tmp; std::copy(constBegin(), constEnd(), std::back_inserter(tmp)); return tmp; }
{ return std::list<T>(begin(), end()); }
#endif
private:
@ -1105,10 +1105,7 @@ inline int QList<T>::count_impl(const T &t, QListData::ArrayCompatibleLayout) co
template <typename T>
Q_OUTOFLINE_TEMPLATE QVector<T> QList<T>::toVector() const
{
QVector<T> result(size());
for (int i = 0; i < size(); ++i)
result[i] = at(i);
return result;
return QVector<T>(begin(), end());
}
template <typename T>
@ -1120,11 +1117,7 @@ QList<T> QList<T>::fromVector(const QVector<T> &vector)
template <typename T>
Q_OUTOFLINE_TEMPLATE QList<T> QVector<T>::toList() const
{
QList<T> result;
result.reserve(size());
for (int i = 0; i < size(); ++i)
result.append(at(i));
return result;
return QList<T>(begin(), end());
}
template <typename T>

View File

@ -303,7 +303,7 @@ public:
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
Q_DECL_DEPRECATED_X("Use QVector<T>(vector.begin(), vector.end()) instead.")
static inline QVector<T> fromStdVector(const std::vector<T> &vector)
{ QVector<T> tmp; tmp.reserve(int(vector.size())); std::copy(vector.begin(), vector.end(), std::back_inserter(tmp)); return tmp; }
{ return QVector<T>(vector.begin(), vector.end()); }
Q_DECL_DEPRECATED_X("Use std::vector<T>(vector.begin(), vector.end()) instead.")
inline std::vector<T> toStdVector() const
{ return std::vector<T>(d->begin(), d->end()); }