Boost logo

Boost :

Subject: Re: [boost] Constructing string_ref from rvalue string
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2017-03-23 21:46:06

On 23/03/2017 20:57, Olaf van der Spek via Boost wrote:
> It's the same underlying issue, replacing const string& by string_view
> doesn't change it.

It does, because it constructs an additional temporary. The compiler
then has an opportunity to destruct the first temporary at the wrong
time. (Which it should not use, if it follows the standard, but that
was the whole point.)

In any case, I think we've bothered the deceased equine enough by now.

>> We were talking about this:
>> void f1(const string_ref&);
>> string f2();
>> f1(f2());
>> Or this:
>> void f1(const string_ref&);
> AFAIK string_ref should be passed by value, not by const&.

It's larger than a pointer. Ergo, pass by reference.

Granted it doesn't make a lot of difference as it's trivial to copy so
that performance isn't much of an issue, but why waste stack/register
space unnecessarily?

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