Boost logo

Boost :

Subject: Re: [boost] Constructing string_ref from rvalue string
From: Bo Persson (bop_at_[hidden])
Date: 2017-03-23 23:42:36

On 2017-03-23 22:46, Gavin Lambert via Boost wrote:
> 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?

How about when *using* the parameter. Effectively passing a reference to
a pointer may not be the best way to get high performance.

     Bo Persson

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