From f89803e459ca02ad4be0c2e1620b80b0cb248642 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 3 Jul 2015 13:24:31 +0200 Subject: Make container move semantics consistent Make all containers (excepting QVarLengthArray) - nothrow default-constructible - nothrow move-constructible - nothrow move-assignable - nothrow swappable [ChangeLog][QtCore] All containers (with the exception of QVarLengthArray, but including QSharedPointer) are now nothrow_default_constructible, nothrow_move_constructible, nothrow_move_assignable, and nothrow-swappable. Change-Id: I12138d262f9f7f600f0e1218137da208c12e7c0a Reviewed-by: Thiago Macieira --- src/corelib/tools/qbitarray.h | 2 +- src/corelib/tools/qhash.h | 4 ++-- src/corelib/tools/qlinkedlist.h | 9 +++++---- src/corelib/tools/qlist.h | 7 ++++--- src/corelib/tools/qmap.h | 12 ++++++------ src/corelib/tools/qqueue.h | 2 +- src/corelib/tools/qset.h | 4 ++-- src/corelib/tools/qstack.h | 2 +- 8 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/corelib/tools/qbitarray.h b/src/corelib/tools/qbitarray.h index 4e5c26b86a..e686d53db4 100644 --- a/src/corelib/tools/qbitarray.h +++ b/src/corelib/tools/qbitarray.h @@ -48,7 +48,7 @@ class Q_CORE_EXPORT QBitArray QByteArray d; public: - inline QBitArray() {} + inline QBitArray() Q_DECL_NOTHROW {} explicit QBitArray(int size, bool val = false); QBitArray(const QBitArray &other) : d(other.d) {} inline QBitArray &operator=(const QBitArray &other) { d = other.d; return *this; } diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h index 8e71925fd9..a18dd74706 100644 --- a/src/corelib/tools/qhash.h +++ b/src/corelib/tools/qhash.h @@ -935,7 +935,7 @@ template class QMultiHash : public QHash { public: - QMultiHash() {} + QMultiHash() Q_DECL_NOTHROW {} #ifdef Q_COMPILER_INITIALIZER_LISTS inline QMultiHash(std::initializer_list > list) { @@ -951,7 +951,7 @@ public: #ifdef Q_COMPILER_RVALUE_REFS QMultiHash(QHash &&other) Q_DECL_NOTHROW : QHash(std::move(other)) {} #endif - void swap(QMultiHash &other) { QHash::swap(other); } // prevent QMultiHash<->QHash swaps + void swap(QMultiHash &other) Q_DECL_NOTHROW { QHash::swap(other); } // prevent QMultiHash<->QHash swaps inline typename QHash::iterator replace(const Key &key, const T &value) { return QHash::insert(key, value); } diff --git a/src/corelib/tools/qlinkedlist.h b/src/corelib/tools/qlinkedlist.h index f216aa121c..2854885d60 100644 --- a/src/corelib/tools/qlinkedlist.h +++ b/src/corelib/tools/qlinkedlist.h @@ -74,7 +74,7 @@ class QLinkedList union { QLinkedListData *d; QLinkedListNode *e; }; public: - inline QLinkedList() : d(const_cast(&QLinkedListData::shared_null)) { } + inline QLinkedList() Q_DECL_NOTHROW : d(const_cast(&QLinkedListData::shared_null)) { } inline QLinkedList(const QLinkedList &l) : d(l.d) { d->ref.ref(); if (!d->sharable) detach(); } #if defined(Q_COMPILER_INITIALIZER_LISTS) inline QLinkedList(std::initializer_list list) @@ -86,11 +86,12 @@ public: ~QLinkedList(); QLinkedList &operator=(const QLinkedList &); #ifdef Q_COMPILER_RVALUE_REFS - inline QLinkedList(QLinkedList &&other) : d(other.d) { other.d = const_cast(&QLinkedListData::shared_null); } - inline QLinkedList &operator=(QLinkedList &&other) + QLinkedList(QLinkedList &&other) Q_DECL_NOTHROW + : d(other.d) { other.d = const_cast(&QLinkedListData::shared_null); } + QLinkedList &operator=(QLinkedList &&other) Q_DECL_NOTHROW { QLinkedList moved(std::move(other)); swap(moved); return *this; } #endif - inline void swap(QLinkedList &other) { qSwap(d, other.d); } + inline void swap(QLinkedList &other) Q_DECL_NOTHROW { qSwap(d, other.d); } bool operator==(const QLinkedList &l) const; inline bool operator!=(const QLinkedList &l) const { return !(*this == l); } diff --git a/src/corelib/tools/qlist.h b/src/corelib/tools/qlist.h index 32e0141d55..9a57a2c6a5 100644 --- a/src/corelib/tools/qlist.h +++ b/src/corelib/tools/qlist.h @@ -143,11 +143,12 @@ public: ~QList(); QList &operator=(const QList &l); #ifdef Q_COMPILER_RVALUE_REFS - inline QList(QList &&other) : d(other.d) { other.d = const_cast(&QListData::shared_null); } - inline QList &operator=(QList &&other) + inline QList(QList &&other) Q_DECL_NOTHROW + : d(other.d) { other.d = const_cast(&QListData::shared_null); } + inline QList &operator=(QList &&other) Q_DECL_NOTHROW { QList moved(std::move(other)); swap(moved); return *this; } #endif - inline void swap(QList &other) { qSwap(d, other.d); } + inline void swap(QList &other) Q_DECL_NOTHROW { qSwap(d, other.d); } #ifdef Q_COMPILER_INITIALIZER_LISTS inline QList(std::initializer_list args) : d(const_cast(&QListData::shared_null)) diff --git a/src/corelib/tools/qmap.h b/src/corelib/tools/qmap.h index df2e5f1caf..fe9ddaaa32 100644 --- a/src/corelib/tools/qmap.h +++ b/src/corelib/tools/qmap.h @@ -321,7 +321,7 @@ class QMap QMapData *d; public: - inline QMap() : d(static_cast *>(const_cast(&QMapDataBase::shared_null))) { } + inline QMap() Q_DECL_NOTHROW : d(static_cast *>(const_cast(&QMapDataBase::shared_null))) { } #ifdef Q_COMPILER_INITIALIZER_LISTS inline QMap(std::initializer_list > list) : d(static_cast *>(const_cast(&QMapDataBase::shared_null))) @@ -336,17 +336,17 @@ public: QMap &operator=(const QMap &other); #ifdef Q_COMPILER_RVALUE_REFS - inline QMap(QMap &&other) + inline QMap(QMap &&other) Q_DECL_NOTHROW : d(other.d) { other.d = static_cast *>( const_cast(&QMapDataBase::shared_null)); } - inline QMap &operator=(QMap &&other) + inline QMap &operator=(QMap &&other) Q_DECL_NOTHROW { QMap moved(std::move(other)); swap(moved); return *this; } #endif - inline void swap(QMap &other) { qSwap(d, other.d); } + inline void swap(QMap &other) Q_DECL_NOTHROW { qSwap(d, other.d); } explicit QMap(const typename std::map &other); std::map toStdMap() const; @@ -1168,7 +1168,7 @@ template class QMultiMap : public QMap { public: - QMultiMap() {} + QMultiMap() Q_DECL_NOTHROW {} #ifdef Q_COMPILER_INITIALIZER_LISTS inline QMultiMap(std::initializer_list > list) { @@ -1180,7 +1180,7 @@ public: #ifdef Q_COMPILER_RVALUE_REFS QMultiMap(QMap &&other) Q_DECL_NOTHROW : QMap(std::move(other)) {} #endif - inline void swap(QMultiMap &other) { QMap::swap(other); } + void swap(QMultiMap &other) Q_DECL_NOTHROW { QMap::swap(other); } inline typename QMap::iterator replace(const Key &key, const T &value) { return QMap::insert(key, value); } diff --git a/src/corelib/tools/qqueue.h b/src/corelib/tools/qqueue.h index 7a7abab070..0cb8353d0f 100644 --- a/src/corelib/tools/qqueue.h +++ b/src/corelib/tools/qqueue.h @@ -44,7 +44,7 @@ class QQueue : public QList { public: // compiler-generated special member functions are fine! - inline void swap(QQueue &other) { QList::swap(other); } // prevent QList<->QQueue swaps + inline void swap(QQueue &other) Q_DECL_NOTHROW { QList::swap(other); } // prevent QList<->QQueue swaps #ifndef Q_QDOC // bring in QList::swap(int, int). We cannot say using QList::swap, // because we don't want to make swap(QList&) available. diff --git a/src/corelib/tools/qset.h b/src/corelib/tools/qset.h index aeba6cf68d..ed89617cd6 100644 --- a/src/corelib/tools/qset.h +++ b/src/corelib/tools/qset.h @@ -48,7 +48,7 @@ class QSet typedef QHash Hash; public: - inline QSet() {} + inline QSet() Q_DECL_NOTHROW {} #ifdef Q_COMPILER_INITIALIZER_LISTS inline QSet(std::initializer_list list) { @@ -60,7 +60,7 @@ public: // compiler-generated copy/move ctor/assignment operators are fine! // compiler-generated destructor is fine! - inline void swap(QSet &other) { q_hash.swap(other.q_hash); } + inline void swap(QSet &other) Q_DECL_NOTHROW { q_hash.swap(other.q_hash); } inline bool operator==(const QSet &other) const { return q_hash == other.q_hash; } diff --git a/src/corelib/tools/qstack.h b/src/corelib/tools/qstack.h index 278e89ca2f..cb72316c32 100644 --- a/src/corelib/tools/qstack.h +++ b/src/corelib/tools/qstack.h @@ -44,7 +44,7 @@ class QStack : public QVector { public: // compiler-generated special member functions are fine! - inline void swap(QStack &other) { QVector::swap(other); } // prevent QVector<->QStack swaps + inline void swap(QStack &other) Q_DECL_NOTHROW { QVector::swap(other); } // prevent QVector<->QStack swaps inline void push(const T &t) { QVector::append(t); } T pop(); T &top(); -- cgit v1.2.3