C++ Logo

std-proposals

Advanced search

Re: Default assignment operators from copy/move constructors

From: Nikolay Mihaylov <nmmm_at_[hidden]>
Date: Fri, 7 Aug 2020 00:08:10 +0300
Isn't assignment works automatically if there is copy c-tor?

https://gcc.godbolt.org/z/bnE4GM

but I agree, if you add move c-tor it stops working

On Thu, Aug 6, 2020 at 11:58 PM Nevin Liber via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Is this a bot? You posted the same thing in 2018.
>
>
> https://groups.google.com/a/isocpp.org/g/std-proposals/c/5BxOQpYzRB4/m/82lMYsJWBQAJ
>
> On Thu, Aug 6, 2020 at 3:49 PM Walt Karas via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>> 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;
>> }
>>
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>
>
> --
> Nevin ":-)" Liber <mailto:nevin_at_[hidden]> +1-847-691-1404
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2020-08-06 16:12:09