C++ Logo

std-proposals

Advanced search

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

From: Maciej Cencora <m.cencora_at_[hidden]>
Date: Mon, 30 May 2022 17:45:15 +0200
Please provide me with an example of an immovable but relocatable
type, that actually makes sense.
I tried to come-up with such a type, but failed.

Regards,
Maciej

pon., 30 maj 2022 o 17:37 Edward Catmur <ecatmur_at_[hidden]> napisaƂ(a):
>
> 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:45:28