void swap(Message &lhs, Message &rhs)
{
using std::swap;
for (auto f : lhs.folders)
f->remMsg(&lhs);
for (auto f : rhs.folders)
f->remMsg(&rhs);
swap(lhs.folders, rhs.folders);
swap(lhs.contents, rhs.contents);
for (auto f : lhs.folders)
f->addMsg(&lhs);
for (auto f : rhs.folders)
f->addMsg(&rhs);
}
However, trying to pass rhs as the second argument in swap gives an error. Removing the const from the parameter in Message& Message::operator=(const Message &rhs) compiles the code.
Because the second parameter of the swap is not a const reference. You may not call functions that have a non-const reference parameter for a const reference argument.
Const means read-only as far as I am aware of and if you are using a reference as a parameter then you are writing to that value so would be hard to write to a read-only value.