From: Peter Dimov (pdimov_at_[hidden])
Date: 2020-09-17 21:02:49
> Vinnie Falco wrote:
> > Just open an issue and explain how you think self-swap, self-move, and
> > self-assignment should work and I will make the changes.
> They should be no-ops.
More specifically, self-swap should be a no-op, and assignments should be
T& operator=( T const& rhs )
T(rhs).swap(*this); return *this;
T& operator=( T&& rhs )
T(std::move(rhs)).swap(*this); return *this;
This is important for classes such as json::value, object, array, where
*this may own rhs, so it's important not to destroy rhs too early. E.g.
v = v.at(0);
v = std::move(v.at(0));
a = a.at(0).as_array();
a = std::move(a.at(0)).as_array();
o = o.at("key").as_object();
o = std::move(o.at("key").as_object());
This is not self-assignment, but it has the same lifetime pitfalls - if you
destroy the old contents of *this, rhs is invalidated, so you can no longer
copy (or move) it.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk