C++ Logo

std-proposals

Advanced search

Default assignment operators from copy/move constructors

From: Walt Karas <wkaras_at_[hidden]>
Date: Thu, 6 Aug 2020 20:49:13 +0000 (UTC)
If a class C has a copy constructor, seems desirable to generate a default copy assign like:


C & operator = (C const &rhs)
{
  if (this != &rhs)
  {

    this->~C();
    ::new (this) C(rhs);
  }
  return *this;
}


Likewise for default move assign when move copy is defined:


C & operator = (C &&rhs)

{
  if (this != &rhs)
  {

    this->~C();
    ::new (this) C(std::move(rhs));
  }
  return *this;
}

Received on 2020-08-06 15:52:42