C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Relocation in C++

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Mon, 30 May 2022 09:37:39 -0600
On Mon, 30 May 2022 at 09:26, Maciej Cencora via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Can't we base relocation on move+destroy only? (or just memcpy + end
> of scope in case of trivially relocatable types).
>
> I.e.:
> Obj a;
> auto b = reloc a;
>
> At 'reloc a' line, we either:
> 1) construct 'b' by invoking move constructor from 'a', invoke
> destructor for 'a', remove 'a' from scope
> 2) construct 'b' by memcpy-ing 'a', do not invoke 'a' destructor,
> remove ab' from scope
>

We expect there to exist types that are immovable and not trivially
relocatable. For a simple example, consider an aggregate with two data
members, one of which is immovable (but trivially relocatable) and the
other is movable (but not trivially relocatable). This means that a
user-defined (non-trivial) relocation operation must exist, and defaulting
it is an attractive way to express that a type is trivially relocatable (if
all its subobject types are also trivially relocatable). Then also, a
nonaggregate type with immovable subobjects may require self-reference
adjustment, so the code for that adjustment should be expressed in the
function body of the relocation operation.

Received on 2022-05-30 15:37:52