Boost logo

Boost :

Subject: Re: [boost] Variadic append for std::string
From: Christof Donat (cd_at_[hidden])
Date: 2017-01-20 14:03:12


Hi,

Am 20.01.2017 10:41, schrieb Hans Dembinski:
> I still think that "join" is a better name for what you call "concat",
> as the function is literally joining various pieces and that name does
> not require an abbreviation. What you call "join" could be called
> "join_sequence".

I think, we should try and go for the least surprise. People coming form
other languages will probably associate with join(), what you call
"join_sequence", while they will expect a name like concat(), operator
+, append(), etc. for what you prefer to call "join".

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:

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.

Christof


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