Boost logo

Boost :

Subject: Re: [boost] Variadic append for std::string
From: Olaf van der Spek (ml_at_[hidden])
Date: 2016-12-31 12:36:12


On Thu, Dec 29, 2016 at 2:53 PM, Andrey Semashev
<andrey.semashev_at_[hidden]> wrote:
>>>> One frequently needs to append stuff to strings, but the standard way
>>>> (s += "A" + "B" + to_string(42)) isn't optimal due to temporaries.
>>>>
>>>
>>> Can't we already write it through (((s += "A") += "B") += to_string(42))?
>>> This is the time I think that assignment operators, other than =, should
>>> have had left associativitiy... pity they don't.
>>
>>
>> We can, but it's ugly and I'd like to avoid the explicit to_string. It
>> also wouldn't allow the two-pass optimization to calculate the final
>> length before allocation.
>
>
> I already mentioned in the std-proposals discussion that I don't think
> formatting should be dealed with by std::string or a function named
> append().

It'd be helpful if you include *why* you think so..

> If formatting is to be involved I'd suggest creating a formatting
> library, but at that point you should provide clear advantages over the
> other formatting libraries we have in Boost.

-- 
Olaf

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk