C++ Logo

std-proposals

Advanced search

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

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Mon, 16 May 2022 07:53:57 +0100
On Sat, 14 May 2022 at 21:37, Sebastian Wittmeier via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> How does the bookkeeping work for automatic variables?
>
>
>
> {
>
> std::string src1 = "hello world";
> for (int i = 0; i < 10; i++)
>
> if (randint(0, 40) == 0) {
> std::string src2 = std::relocate(src1);
>
> break;
>
> }
>
> // what if we use it here?
>
> // std::cout << src1;
>
> }
>
>
>
> Is a flag or bool saved together with each automatic variable, which could
> be relocated?
>
>
>
> The compiler would not be able to catch each usage after relocate in
> compile time.
>
>
>
> However this is solved, a std::relocate call could be used without a new
> object. How does this work with the operator reloc syntax?
>

I'm not sure which proposal or proposals you are referring to. If you want
dynamic lifetime tracking you can just use std::optional. The strength of
operator reloc is that it removes the identifier from lexical scope; it is
not a dynamic operation per se.

Received on 2022-05-16 06:54:09