diff --git a/src/blackmisc/collection.h b/src/blackmisc/collection.h index e11d1489e..4286881e5 100644 --- a/src/blackmisc/collection.h +++ b/src/blackmisc/collection.h @@ -98,7 +98,7 @@ namespace BlackMisc /*! * \brief Move constructor. */ - CCollection(CCollection &&other) : m_pimpl(other.m_pimpl.take()) {} + CCollection(CCollection &&other) noexcept(std::is_nothrow_move_constructible::value) : m_pimpl(other.m_pimpl.take()) {} /*! * \brief Copy assignment. @@ -108,7 +108,7 @@ namespace BlackMisc /*! * \brief Move assignment. */ - CCollection &operator =(CCollection && other) { m_pimpl.reset(other.m_pimpl.take()); return *this; } + CCollection &operator =(CCollection && other) noexcept(std::is_nothrow_move_assignable::value) { m_pimpl.reset(other.m_pimpl.take()); return *this; } /*! * \brief Create a new collection with a specific implementation type. @@ -162,7 +162,7 @@ namespace BlackMisc /*! * \brief Swap this collection with another. */ - void swap(CCollection &other) { m_pimpl.swap(other.m_pimpl); } + void swap(CCollection &other) noexcept { m_pimpl.swap(other.m_pimpl); } /*! * \brief Returns number of elements in the collection. diff --git a/src/blackmisc/datacache.cpp b/src/blackmisc/datacache.cpp index 60d897d07..0e7fecd98 100644 --- a/src/blackmisc/datacache.cpp +++ b/src/blackmisc/datacache.cpp @@ -29,8 +29,8 @@ namespace BlackMisc public: LockGuard(const LockGuard &) = delete; LockGuard &operator =(const LockGuard &) = delete; - LockGuard(LockGuard &&other) : m_movedFrom(true) { *this = std::move(other); } - LockGuard &operator =(LockGuard &&other) { std::swap(m_movedFrom, other.m_movedFrom); std::swap(m_rev, other.m_rev); return *this; } + LockGuard(LockGuard &&other) noexcept : m_movedFrom(true) { *this = std::move(other); } + LockGuard &operator =(LockGuard &&other) noexcept { std::swap(m_movedFrom, other.m_movedFrom); std::swap(m_rev, other.m_rev); return *this; } ~LockGuard() { diff --git a/src/blackmisc/dictionary.h b/src/blackmisc/dictionary.h index c146d8a1e..606cd419f 100644 --- a/src/blackmisc/dictionary.h +++ b/src/blackmisc/dictionary.h @@ -274,7 +274,7 @@ namespace BlackMisc CDictionary(const CDictionary &) = default; //! Move constructor - CDictionary(CDictionary &&other) : m_impl(std::move(other.m_impl)) {} + CDictionary(CDictionary &&other) noexcept : m_impl(std::move(other.m_impl)) {} //! Virtual destructor virtual ~CDictionary() {} @@ -367,7 +367,7 @@ namespace BlackMisc int size() const { return m_impl.size(); } //! Swaps hash other with this hash. This operation is very fast and never fails. - void swap(CDictionary &other) { m_impl.swap(other.m_impl); } + void swap(CDictionary &other) noexcept { m_impl.swap(other.m_impl); } //! Returns the value associated with the key. const Value value(const Key &key) const { return m_impl.value(key); } @@ -382,7 +382,7 @@ namespace BlackMisc CDictionary &operator =(const CDictionary &other) { m_impl = other.m_impl; return *this; } //! Move assignment - CDictionary &operator =(CDictionary && other) { m_impl = std::move(other.m_impl); return *this; } + CDictionary &operator =(CDictionary && other) noexcept { m_impl = std::move(other.m_impl); return *this; } //! Return reference to the internal implementation object. friend impl_type &implementationOf(CDictionary &dict) { return dict.m_impl; } diff --git a/src/blackmisc/iterator.h b/src/blackmisc/iterator.h index 6f3014b33..af3f15272 100644 --- a/src/blackmisc/iterator.h +++ b/src/blackmisc/iterator.h @@ -321,7 +321,7 @@ namespace BlackMisc /*! * \brief Move constructor. */ - ConstForwardIterator(ConstForwardIterator &&other) : m_pimpl(other.m_pimpl.take()) {} + ConstForwardIterator(ConstForwardIterator &&other) noexcept : m_pimpl(other.m_pimpl.take()) {} /*! * \brief Copy assignment. @@ -331,7 +331,7 @@ namespace BlackMisc /*! * \brief Move assignment. */ - ConstForwardIterator &operator =(ConstForwardIterator &&other) { m_pimpl.reset(other.m_pimpl.take()); return *this; } + ConstForwardIterator &operator =(ConstForwardIterator &&other) noexcept { m_pimpl.reset(other.m_pimpl.take()); return *this; } /*! * \brief Create a new iterator with a specific implementation type. @@ -469,7 +469,7 @@ namespace BlackMisc /*! * \brief Move constructor. */ - ConstBidirectionalIterator(ConstBidirectionalIterator &&other) : m_pimpl(other.m_pimpl.take()) {} + ConstBidirectionalIterator(ConstBidirectionalIterator &&other) noexcept : m_pimpl(other.m_pimpl.take()) {} /*! * \brief Copy assignment. @@ -479,7 +479,7 @@ namespace BlackMisc /*! * \brief Move assignment. */ - ConstBidirectionalIterator &operator =(ConstBidirectionalIterator &&other) { m_pimpl.reset(other.m_pimpl.take()); return *this; } + ConstBidirectionalIterator &operator =(ConstBidirectionalIterator &&other) noexcept { m_pimpl.reset(other.m_pimpl.take()); return *this; } /*! * \brief Create a new iterator with a specific implementation type. @@ -676,7 +676,7 @@ namespace BlackMisc /*! * \brief Move constructor. */ - BidirectionalIterator(BidirectionalIterator &&other) : m_pimpl(other.m_pimpl.take()) {} + BidirectionalIterator(BidirectionalIterator &&other) noexcept : m_pimpl(other.m_pimpl.take()) {} /*! * \brief Copy assignment. @@ -686,7 +686,7 @@ namespace BlackMisc /*! * \brief Move assignment. */ - BidirectionalIterator &operator =(BidirectionalIterator &&other) { m_pimpl.reset(other.m_pimpl.take()); return *this; } + BidirectionalIterator &operator =(BidirectionalIterator &&other) noexcept { m_pimpl.reset(other.m_pimpl.take()); return *this; } /*! * \brief Create a new iterator with a specific implementation type. diff --git a/src/blackmisc/lockfree.h b/src/blackmisc/lockfree.h index 8ad788eac..2c6c562c6 100644 --- a/src/blackmisc/lockfree.h +++ b/src/blackmisc/lockfree.h @@ -123,7 +123,7 @@ namespace BlackMisc LockFreeUniqueWriter &operator =(const T &other) { *m_ptr = other; return *this; } //! Replace the stored value by moving from a T. The change is applied in the destructor. - LockFreeUniqueWriter &operator =(T &&other) { *m_ptr = std::move(other); return *this; } + LockFreeUniqueWriter &operator =(T &&other) noexcept(std::is_nothrow_move_assignable::value) { *m_ptr = std::move(other); return *this; } //! LockFreeUniqueWriter cannot be copied. //! @{ @@ -132,10 +132,10 @@ namespace BlackMisc //! @} //! Move constructor. - LockFreeUniqueWriter(LockFreeUniqueWriter &&other) : m_old(std::move(other.m_old)), m_now(std::move(other.m_now)), m_ptr(std::move(other.m_ptr)) {} + LockFreeUniqueWriter(LockFreeUniqueWriter &&other) noexcept : m_old(std::move(other.m_old)), m_now(std::move(other.m_now)), m_ptr(std::move(other.m_ptr)) {} //! Move assignment operator. - LockFreeUniqueWriter &operator =(LockFreeUniqueWriter &&other) + LockFreeUniqueWriter &operator =(LockFreeUniqueWriter &&other) noexcept { std::tie(m_old, m_now, m_ptr) = std::forward_as_tuple(std::move(other.m_old), std::move(other.m_now), std::move(other.m_ptr)); return *this; @@ -180,7 +180,7 @@ namespace BlackMisc LockFreeSharedWriter &operator =(const T &other) { *m_ptr = other; return *this; } //! Replace the stored value by moving from a T. The change is applied by evaluating in a bool context. - LockFreeSharedWriter &operator =(T &&other) { *m_ptr = std::move(other); return *this; } + LockFreeSharedWriter &operator =(T &&other) noexcept(std::is_nothrow_move_assignable::value) { *m_ptr = std::move(other); return *this; } //! Try to overwrite the original object with the new one stored in the writer, and return false on success. //! If true is returned, then the caller must try again. This would happen if another simultaneous write had occurred. @@ -215,10 +215,10 @@ namespace BlackMisc //! @} //! Move constructor. - LockFreeSharedWriter(LockFreeSharedWriter &&other) : m_old(std::move(other.m_old)), m_now(std::move(other.m_now)), m_ptr(std::move(other.m_ptr)) {} + LockFreeSharedWriter(LockFreeSharedWriter &&other) noexcept : m_old(std::move(other.m_old)), m_now(std::move(other.m_now)), m_ptr(std::move(other.m_ptr)) {} //! Move assignment operator. - LockFreeSharedWriter &operator =(LockFreeSharedWriter &&other) + LockFreeSharedWriter &operator =(LockFreeSharedWriter &&other) noexcept { std::tie(m_old, m_now, m_ptr) = std::forward_as_tuple(std::move(other.m_old), std::move(other.m_now), std::move(other.m_ptr)); return *this; @@ -251,7 +251,7 @@ namespace BlackMisc LockFree(const T &other) : m_ptr(std::make_shared(other)) {} //! Construct by moving from a T. - LockFree(T &&other) : m_ptr(std::make_shared(std::move(other))) {} + LockFree(T &&other) noexcept(std::is_nothrow_move_assignable::value) : m_ptr(std::make_shared(std::move(other))) {} //! LockFree cannot be copied or moved. //! @{ diff --git a/src/blackmisc/optional.h b/src/blackmisc/optional.h index 25476879c..dda5f641b 100644 --- a/src/blackmisc/optional.h +++ b/src/blackmisc/optional.h @@ -41,7 +41,7 @@ namespace BlackMisc } //! Move constructor. - Optional(Optional &&other) : m_isValid(other.m_isValid) + Optional(Optional &&other) noexcept(std::is_nothrow_move_constructible::value) : m_isValid(other.m_isValid) { if (other.m_isValid) { new (m_data.bytes) T(std::move(*other)); } } @@ -64,7 +64,7 @@ namespace BlackMisc } //! Move assignment. - Optional &operator =(Optional &&other) + Optional &operator =(Optional &&other) noexcept(std::is_nothrow_move_assignable::value) { if (m_isValid) { (*this)->~T(); } if (other.m_isValid) { new (m_data.bytes) T(std::move(*other)); } @@ -113,6 +113,7 @@ namespace BlackMisc /*! * Efficient swap for two Optional objects. + * \todo Make conditionally noexcept using C++17 std::is_nothrow_swappable. */ template void swap(Optional &a, Optional &b) diff --git a/src/blackmisc/sequence.h b/src/blackmisc/sequence.h index 16ea75bb9..0ea50aaca 100644 --- a/src/blackmisc/sequence.h +++ b/src/blackmisc/sequence.h @@ -74,7 +74,7 @@ namespace BlackMisc /*! * \brief Move constructor. */ - CSequence(CSequence &&other) : m_pimpl(other.m_pimpl.take()) {} + CSequence(CSequence &&other) noexcept(std::is_nothrow_move_constructible::value) : m_pimpl(other.m_pimpl.take()) {} /*! * \brief Copy assignment. @@ -84,7 +84,7 @@ namespace BlackMisc /*! * \brief Move assignment. */ - CSequence &operator =(CSequence && other) { m_pimpl.reset(other.m_pimpl.take()); return *this; } + CSequence &operator =(CSequence && other) noexcept(std::is_nothrow_move_assignable::value) { m_pimpl.reset(other.m_pimpl.take()); return *this; } /*! * \brief Create a new sequence with a specific implementation type. @@ -138,7 +138,7 @@ namespace BlackMisc /*! * \brief Swap this sequence with another. */ - void swap(CSequence &other) { m_pimpl.swap(other.m_pimpl); } + void swap(CSequence &other) noexcept { m_pimpl.swap(other.m_pimpl); } /*! * \brief Access an element by its index. diff --git a/src/blackmisc/valuecache.h b/src/blackmisc/valuecache.h index 929099cf1..296e99adf 100644 --- a/src/blackmisc/valuecache.h +++ b/src/blackmisc/valuecache.h @@ -354,10 +354,10 @@ namespace BlackMisc BatchGuard &operator =(const BatchGuard &) = delete; //! Move constructor. - BatchGuard(BatchGuard &&other) : m_page(other.m_page) { other.m_page = nullptr; } + BatchGuard(BatchGuard &&other) noexcept : m_page(other.m_page) { other.m_page = nullptr; } //! Move assignment operator. - BatchGuard &operator =(BatchGuard &&other) { std::swap(m_page, other.m_page); return *this; } + BatchGuard &operator =(BatchGuard &&other) noexcept { std::swap(m_page, other.m_page); return *this; } private: friend class CValueCache; diff --git a/src/blackmisc/variant.h b/src/blackmisc/variant.h index 421ed1579..c20658b28 100644 --- a/src/blackmisc/variant.h +++ b/src/blackmisc/variant.h @@ -129,13 +129,13 @@ namespace BlackMisc CVariant(const CVariant &) = default; //! Move constructor. - CVariant(CVariant &&other) : m_v(std::move(other.m_v)) {} + CVariant(CVariant &&other) noexcept : m_v(std::move(other.m_v)) {} //! Construct from a QVariant. CVariant(const QVariant &var) : m_v(var) {} //! Move-construct from a QVariant. - CVariant(QVariant &&var) : m_v(std::move(var)) {} + CVariant(QVariant &&var) noexcept : m_v(std::move(var)) {} //! Construct a null variant of the given type. CVariant(QVariant::Type type) : m_v(type) {} @@ -165,19 +165,19 @@ namespace BlackMisc CVariant &operator =(const CVariant &other) { m_v = other.m_v; return *this; } //! Move assignment operatior. - CVariant &operator =(CVariant && other) { m_v = std::move(other.m_v); return *this; } + CVariant &operator =(CVariant && other) noexcept { m_v = std::move(other.m_v); return *this; } //! Change the internal QVariant CVariant &operator =(const QVariant &var) { m_v = var; return *this; } //! Change the internal QVariant - CVariant &operator =(QVariant && var) { m_v = std::move(var); return *this; } + CVariant &operator =(QVariant && var) noexcept { m_v = std::move(var); return *this; } //! Swap this variant with another. - void swap(CVariant &other) { m_v.swap(other.m_v); } + void swap(CVariant &other) noexcept { m_v.swap(other.m_v); } //! Swap the internal QVariant with another. - void swap(QVariant &other) { m_v.swap(other); } + void swap(QVariant &other) noexcept { m_v.swap(other); } //! Construct a variant from a value. template static CVariant fromValue(T &&value) diff --git a/src/blackmisc/variantmap.h b/src/blackmisc/variantmap.h index 1f4e98aee..bc8368f5d 100644 --- a/src/blackmisc/variantmap.h +++ b/src/blackmisc/variantmap.h @@ -40,13 +40,13 @@ namespace BlackMisc CVariantMap(const CVariantMap &) = default; //! Move constructor. - CVariantMap(CVariantMap &&other) : CDictionary(std::move(other)) {} + CVariantMap(CVariantMap &&other) noexcept : CDictionary(std::move(other)) {} //! Copy assignment operator. CVariantMap &operator =(const CVariantMap &other) { CDictionary::operator =(other); return *this; } //! Move assignment operator. - CVariantMap &operator =(CVariantMap &&other) { CDictionary::operator =(std::move(other)); return *this; } + CVariantMap &operator =(CVariantMap &&other) noexcept { CDictionary::operator =(std::move(other)); return *this; } //! \copydoc BlackMisc::CValueObject::toJson QJsonObject toJson() const;