Boost logo

Boost :

Subject: Re: [boost] boost::algorithm::trim_copy() behaves like "strdup" in normal C, does it allocate a new string ?
From: Lars Viklund (zao_at_[hidden])
Date: 2012-03-10 08:33:33

On Sat, Mar 10, 2012 at 01:58:22PM +0100, Olaf van der Spek wrote:
> On Sat, Mar 10, 2012 at 12:19 PM, Lars Viklund <zao_at_[hidden]> wrote:
> > On Fri, Mar 09, 2012 at 07:14:24PM +0100, g.fanini_at_[hidden] wrote:
> >> Could I ask for a clarification whether boost::algorithm::trim_copy()
> >> behaves like "strdup" in normal C, i.e. does it allocate a new string ? or
> >> does it modify the passed string without allocating a new string ?
> >
> > As the parameter is const, it cannot cast the const away to mutate it
> > unless it knows things about the argument at the call site, which it
> > cannot know.
> Hmm, wouldn't a by-value parameter allow one to avoid the copy?

What copy? The current signature is most probably one of the most
optimal ones, considering that NRVO is a very common optimization to
elide the copy of the returned value.

The only benefit you would gain from changing the parameter to be
by-value is that you could work in-place, but as the Sequence concept
used doesn't include shrinking from either side, you still need to make
copy into a fresh return value in order to have something to return.

Or was the 'by-value' a typo for passing by reference to non-const,
working in-place? If so, you still have the problem of not being able to
express a truncation in the Sequence concept.

> > Also, you're using very ancient documentation there, are you really on
> > 1.34 or just using the wrong documentation?
> It's still the first hit on google...

While unfortunate, one should still aim to use documentation that
matches the version you're attempting to use.

Ret-conning a note into old documentation indicating that it's not
current might be beneficial, but considering that there's many
documentation systems involved in Boost docs, it might not be
universally feasible.

There's some limited redirects out there for some doc revisions, but I'm
unsure of the exact semantics.

Lars Viklund | zao_at_[hidden]

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