Boost logo

Boost :

Subject: Re: [boost] Variadic append for std::string
From: Hans Dembinski (hans.dembinski_at_[hidden])
Date: 2017-01-23 10:32:51


> On 23 Jan 2017, at 11:23, Christof Donat <cd_at_[hidden]> wrote:
>
> Hi,
>
> Am 23.01.2017 09:55, schrieb Hans Dembinski:
>> On 20 Jan 2017, at 20:03, Christof Donat <cd_at_[hidden]> wrote:
>>> auto my_new_str = concat("Hello", ", ", "World", "!").str();
>>> [...]
>> Your last proposal was without the ".str()", which made more sense:
>> auto my_new_str = concat("Hello", ", ", "World", "!");
>> I hope this was just a typo.
>
> Actually no, it wasn't. The idea is, that functions like concat(), join() and format() return string factories, instead of strings. This is an advantage, when you combine calls to these functions:
>
> auto my_new_str =
> concat("Hello ",
> join(", ",std::begin(my_nums), std::end(my_nums)),
> format(" the file %1% contains %2% bytes", filename, filesize)).str();

It makes sense to me for "join" to return a string factory, because it is likely to be nested in "concat". But I don't see the practical case of nested "concat" calls, at least it is not going to be a common pattern in the need of optimising.

If "concat" is the outer layer anyway, I would return a std::string directly for convenience. It is easy to forget the trailing .str() and it does not look elegant.


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