Boost logo

Boost :

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

> On 20 Jan 2017, at 20:03, Christof Donat <cd_at_[hidden]> wrote:
> So the least surprise is, I still think, with concat(a, b, c, d) and join(separator, sequence), just as with C#, JavaScript. With Qt and Python you use append() or operator + instead of concat(), but join() is consistent with them as well. The advantage of concat() over the operator + on strings in C++ is, that concat() can easily be implemented in a much more efficient way with less realloc()s and therefore less data copying. At lesst, when we don't want to have an API like this:

I agree with the principle of least surprise, it is something I am also applying. :) I think that "join" is less surprising, but it looks like the evidence is against me, so I stand down.

> auto my_new_str = (cat() + "Hello" + ", " + "World" + "!").str();
> Here cat() would return a string factory type, that collects all the stuff, that you "add" to it. In str() it allocates a string big enough for all the content and renders in there. Well compared to
> auto my_new_str = concat("Hello", ", ", "World", "!").str();
> Judge for yourself, which one is easier for the user to understand.

Oh, I never questioned this. I see the obvious technical and stylistic advantages of the latter. I am just arguing about names.

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.

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