`std::scoped_lock` is a variadic RAII template for acquiring one or more lockable objects. For multiple mutexes, its constructor uses the same algorithm as `std::lock`; when construction completes, all supplied mutexes are locked, and the destructor unlocks them. section 3.2.4
void swap(X& lhs, X& rhs)
{
if(&lhs==&rhs)
return;
std::scoped_lock guard(lhs.m,rhs.m); #1
swap(lhs.some_detail,rhs.some_detail);
}
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":4,\"ch\":51},{\"line\":4,\"ch\":53}]]"}
!@%STYLE%@!
In this swap operation, one guard acquires both object mutexes before the protected data is swapped; its destruction releases them. section 3.2.4
C++17 class template argument deduction can infer the mutex types from the constructor arguments. Acquiring several locks together can help avoid deadlock, but `std::scoped_lock` does not prevent deadlock when locks are acquired separately. section 3.2.4
