C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: DestructorConstructor - a class destructor with parameter
From: Edward Catmur (ecatmur_at_[hidden])
Date: 2021-02-11 13:02:41


The initial proposal in this thread appears to be the "destructor-like
syntax" mentioned by Denis Bider in P0023 "Relocator: Efficiently moving
objects"[1]. I think the arguments in that paper against the syntax are
still applicable:

  This would operate very similarly to the current proposal, but with the
> possibly unintuitive difference that the new object is being passed as the
> parameter, so that e.g. ~c(x.c) initializes x.c with the value of c.
> Furthermore, it would require re-inventing syntax to allow for move
> construction of subobjects.

I think it's unfortunate that more recent proposals (P1029, P1144) have
moved away from making destructive move a customization point; it should be
entirely possible to square the circle and have efficient relocation (en
bloc memcpy for vector, e.g.) along with user controlled relocate where
necessary. My proposal would be for a new type of constructor, taking a tag
type so as not to require any new syntax, that could be defaulted to attest
that a class is trivially relocatable on condition all its subobjects are:

A(std::relocates, A* ptr) : member(std::relocate(&c->member)) ... { /*
fixup */ }
B(std::relocates, B*) = default;

1. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0023r0.pdf

On Thu, Feb 11, 2021 at 11:06 AM Marcin Jaczewski via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> ś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).
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups