C++ Logo


Advanced search

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

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Sun, 5 Jun 2022 21:58:02 +0100
On Fri, 3 Jun 2022 at 18:28, Magnus Fromreide <magfr_at_[hidden]> wrote:

> How does destroy+relocate assignment work when the assignment is a
> self-assignment?

That shouldn't happen, regardless of the implementation of the value
assignment operator. a = reloc a; is ill-formed, since reloc a removes a
from scope so it can't appear elsewhere in the same statement-expression.
auto& r = a; r = reloc a; is ill-formed NDR, I think, as are a =
std::relocate(&a) and std::relocate_at(&a, &a) (the latter because its
postconditions are inconsistent).

If a relocate constructor is spelled T(T) then how does it work when more
> than one type is involved, is
> A(B)
> a relocating constructor for A that takes a B?
> If it isn't, then how should that be written?

There's no such thing, any more than there is a copy constructor for A that
takes B: A(B const&) is a converting constructor, not a copy constructor,
and likewise A(B) is a converting constructor, not a relocating constructor.

Received on 2022-06-05 20:58:15