On Sat, 14 May 2022 at 21:37, Sebastian Wittmeier via Std-Proposals <std-proposals@lists.isocpp.org> 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.