std::unique_lock::operator= - cppreference.com (original) (raw)

| unique_lock& operator=( unique_lock&& other ) noexcept; | | (since C++11) | | ---------------------------------------------------------- | | ------------- |

Move assignment operator. Equivalent to unique_lock{std::move(other)}.swap(*this); return *this;.

If other is the same object as *this, there is no effect. Otherwise, if prior to the call *this has an associated mutex and has acquired ownership of it, the mutex is unlocked.

[edit] Parameters

other - another unique_lock to replace the state with

[edit] Return value

*this

[edit] Notes

With a recursive mutex it is possible for both *this and other to own the same mutex before the assignment. In this case, *this will own the mutex after the assignment and other will not.

The move assignment possibly raises undefined behavior. For example, when *this is constructed with std::adopt_lock, but the calling thread does not have the ownership of the associated mutex, the ownership of the associated mutex cannot be properly released.

[edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 2104 C++11 the move assignment operator was noexcept but could have undefined behavior noexcept removed
LWG 4172 C++11 LWG2104 removed noexceptself-move-assignment of unique_lock was incorrectly specified noexcept restoredrespecified as no-op