Suppose we have a class with a std::mutex:
class
std::mutex
class Foo { std::mutex mutex_; std::string str_; // other members etc public:
I don't think your swap implementation is safe. If another algorithm tries to lock rhs.mutex_ first and then lhs.mutex_, you may end up with a deadlock. Try std::lock() instead.
rhs.mutex_
lhs.mutex_