C++ Logo

std-discussion

Advanced search

Re: DestructorConstructor - a class destructor with parameter

From: Maciej Polanski <maciejpolanski75_at_[hidden]>
Date: Thu, 11 Feb 2021 18:25:04 +0100
On 2021-02-11 12:06, Marcin Jaczewski via Std-Discussion wrote:
>
> My favorite is:
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1029r3.pdf
> It make effecitve "destructive move" using AS-IF rule becasue moved
> out object dectructor is noop.
> In case of vector you can simply `memcpy` data and only deallocate old memory
> (same effect as value init all old memory and then calling destructor
> and deallocation).

Thanks, I didn't know this proposal!

But I do not think it allows me to freely "memcpy", as elison depends on
compiler optimization and I do not know result of it.

It seems that having "bitcopies" constructor does not guarantee empty
destructor, nor lack of side effects of destructing empty object. It had
to be found by compiler during optimization.

Correct me if I am wrong, but if I was a library programmer, I wouldn't
be able to find if I am allowed to memcpy of given class or not. Solely
having "bitcopies" constructor is not enough.

Thanks,
Maciej

Received on 2021-02-11 11:25:20