C++ Logo

std-proposals

Advanced search

Re: Default assignment operators from copy/move constructors

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 7 Aug 2020 20:56:57 +0300
On Fri, 7 Aug 2020 at 20:47, Walt Karas via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> You can't do a destroy+placement-new if the placement-new can throw.
>
> WK: OK, also good point. If the constructor can throw, then conceptually the default assign can be like this: https://godbolt.org/z/jvdf53

That approach doesn't work for anything non-trivial, and requires
C++20 implicit object creation otherwise.

Again,
> Go read Sutter's Exceptional C++
> and More Exceptional C++, and try again.

The insinuation here is that you're not going to try again, once you
understand that you can't do this in general,
except for trivial types. You need a temporary object and a trivial
swap, and then you don't always want that
temporary, so such a default wouldn't be generally useful.

Received on 2020-08-07 13:00:47