Date: Fri, 11 Apr 2025 17:40:35 +0100
On Friday, April 11, 2025, Ell wrote:
>
>
> I mean that wanting to move a variable upon last use is independent of
> whether it's a reference or a function parameter. In your example, why
> should you need to introduce a reference in the first place? You might
> want to explicitly mark the variable somehow to opt into this
> behavior... or maybe not?
>
The 'mark' you speak of could be the same as how I've suggested marking a
reference, i.e.:
string &&&s("Hello World");
string &&&s2 = "HelloWorld";
This would be similar to how we programmed before C++11, back when we
extended the lifetime of a temporary object by binding it to a const
reference, as follows:
string const &s = FuncReturnsStringByValue();
The above line nowadays is simply written as:
string s = FuncReturnsStringByValue();
>
>
> I mean that wanting to move a variable upon last use is independent of
> whether it's a reference or a function parameter. In your example, why
> should you need to introduce a reference in the first place? You might
> want to explicitly mark the variable somehow to opt into this
> behavior... or maybe not?
>
The 'mark' you speak of could be the same as how I've suggested marking a
reference, i.e.:
string &&&s("Hello World");
string &&&s2 = "HelloWorld";
This would be similar to how we programmed before C++11, back when we
extended the lifetime of a temporary object by binding it to a const
reference, as follows:
string const &s = FuncReturnsStringByValue();
The above line nowadays is simply written as:
string s = FuncReturnsStringByValue();
Received on 2025-04-11 16:40:37