Boost logo

Boost :

Subject: Re: [boost] Constructing string_ref from rvalue string
From: Olaf van der Spek (ml_at_[hidden])
Date: 2017-03-22 14:28:59

On Mon, Mar 20, 2017 at 11:57 PM, Gavin Lambert via Boost
<boost_at_[hidden]> wrote:
> On 20/03/2017 16:14, Tim Song wrote:
>> On Sun, Mar 19, 2017 at 10:42 PM, Gavin Lambert wrote:
>>> If you are calling a function that returns a std::string (thus you have
>>> an
>>> rvalue temporary) and you are immediately wrapping this in a string_ref
>>> (as
>>> another temporary) and then passing this as a function parameter, AFAIK
>>> the
>>> compiler is within its rights to delete the temporary std::string prior
>>> to
>>> the call as it is not the actual parameter.
>> Nope. Those temporaries live until the end of the enclosing
>> full-expression.
> Well, yes, in theory. Though I've been burned in the past by some (older)
> compilers doing it wrong in these sorts of cases, so that usage makes me
> nervous. Any modern compiler shouldn't have an issue with it though.

void f2(const string&);
string f1();


Isn't this a very common pattern?


Boost list run by bdawes at, gregod at, cpdaniel at, john at