summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qvector.h
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-10-10 08:51:04 +0200
committerLars Knoll <lars.knoll@qt.io>2019-05-07 14:15:37 +0000
commitd510e1e7f919e01a3b875ff5a575b818e5ee03e8 (patch)
tree7ce9828d3e7f2867477736f2609762fb2977a56c /src/corelib/tools/qvector.h
parent587bdd144b7e574e57f17167808774fa9783ee78 (diff)
Add swapItemsAt() to QVector
This closes one compatibility gap with QList, to make it easier to replace QList with QVector in Qt6. Change-Id: I5655bc4cd2150a6f09a1ed68c0742f3b42ca47e4 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/corelib/tools/qvector.h')
-rw-r--r--src/corelib/tools/qvector.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/corelib/tools/qvector.h b/src/corelib/tools/qvector.h
index 4e148c9c55..b763d6e7e2 100644
--- a/src/corelib/tools/qvector.h
+++ b/src/corelib/tools/qvector.h
@@ -251,6 +251,13 @@ public:
T value(int i) const;
T value(int i, const T &defaultValue) const;
+ void swapItemsAt(int i, int j) {
+ Q_ASSERT_X(i >= 0 && i < size() && j >= 0 && j < size(),
+ "QVector<T>::swap", "index out of range");
+ detach();
+ qSwap(d->begin()[i], d->begin()[j]);
+ }
+
// STL compatibility
typedef T value_type;
typedef value_type* pointer;