C++ Logo

std-discussion

Advanced search

Re: DestructorConstructor - a class destructor with parameter

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Thu, 11 Feb 2021 12:06:19 +0100
śr., 10 lut 2021 o 23:03 Thiago Macieira via Std-Discussion
<std-discussion_at_[hidden]> napisał(a):
>
> On Wednesday, 10 February 2021 13:52:07 PST Maciej Polanski via Std-Discussion
> wrote:
> > I would like to present a (revolutionary?) concept of
> > "DestructorConstructor", a class destructor with parameter -
> > uninitialized object. Such destructor and constructor in one, while
> > destructing its (own) object, moves data to new (parameter) object with
> > cost of "C" styled "memcpy".
> > I've been thinking about this concept for some time. I have trouble
> > completing it, but I think it is sufficiently valuable to present it to
> > community... even if only to be shown I am a moron
>
> See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4034.pdf and
> other proposals for "destructive move".
>

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).

Received on 2021-02-11 05:06:30