|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
unique_lock::operator= | ||||
| Locking | ||||
| Modifiers | ||||
| Observers | ||||
| Non-member functions | ||||
unique_lock& operator=( unique_lock&& other)noexcept; | (since C++11) | |
Move assignment operator. Equivalent tounique_lock{std::move(other)}.swap(*this);return*this;.
Ifother 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.
Contents |
| other | - | anotherunique_lock to replace the state with |
*this
With a recursive mutex it is possible for both*this andother to own the same mutex before the assignment. In this case,*this will own the mutex after the assignment andother will not.
The move assignment possibly raises undefined behavior. For example, when*this is constructed withstd::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.
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 wasnoexcept but could have undefined behavior | noexcept removed |
| LWG 4172 | C++11 | LWG2104 removednoexcept self-move-assignment of unique_lock was incorrectly specified | noexcept restored respecified as no-op |