...
| Code Block | ||||
|---|---|---|---|---|
| ||||
T(T &&rhs) { *this = std::move(rhs); }
// ... everything except operator= ..
T& operator=(T &&rhs) noexcept {
using std::swap;
swap(n, rhs.n);
swap(s1, rhs.s1);
return *this;
}
T& operator=(const T &rhs) noexcept {
T temp(rhs);
*this = std::move(temprhs.swap(*this);
return *this;
} |
The copy assignment operator uses std::move() rather than swap() to achieve safe self-assignment and a strong exception guarantee. The move assignment operator uses a move (via the method parameter) and swap.
...