Boost logo

Boost :

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
equivalent to:

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 = std::move(;

    a =;
    a = std::move(;

    o ="key").as_object();
    o = std::move("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, gregod at, cpdaniel at, john at