mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
refs #624 Swap functions, move constructors, and move assignment operators should all be noexcept where possible.
This commit is contained in:
@@ -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<T>::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<T>::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.
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<T>::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<T>::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<const T>(other)) {}
|
||||
|
||||
//! Construct by moving from a T.
|
||||
LockFree(T &&other) : m_ptr(std::make_shared<const T>(std::move(other))) {}
|
||||
LockFree(T &&other) noexcept(std::is_nothrow_move_assignable<T>::value) : m_ptr(std::make_shared<const T>(std::move(other))) {}
|
||||
|
||||
//! LockFree cannot be copied or moved.
|
||||
//! @{
|
||||
|
||||
@@ -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<T>::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<T>::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 <typename T>
|
||||
void swap(Optional<T> &a, Optional<T> &b)
|
||||
|
||||
@@ -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<T>::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<T>::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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 <typename T> static CVariant fromValue(T &&value)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user