Hi, Am 11.01.2017 16:03, schrieb Olaf van der Spek:
On Wed, Jan 11, 2017 at 10:02 AM, Christof Donat
wrote: The significantly better alternative is std::ostringstream. I think our debate showed very nicely, that all the options, we have come up with to simplify the concatenation of strings are significantly inferior in total, though we could find examples, where they slightly improve readability.
Interface is important, as is performance.. and performence of ostringstream sucks..
Well, but obviously up to now we didn't manage to come up with a
solution, that has a similar simple, maybe even better interface and
allows for faster implementations.
I'll try again:
Basically the Idea of that kind of interface should work as well for a
high performance solution. Let's start with this syntax:
auto myString = (cat() + "Hello"s + " "s + "World! "s + 42).str();
"cat" would return an object that collects all the values by reference,
and concatenates them in one go in the call to str(). Then when str()
runs, the information about the string length can be calculated, or at
least estimated correctly and no data needs to be copied unnecessarily.
I am sure, you see the structural similarity to the usage of
std::ostringstream as well. I just chose to use the operator +, because
1. we don't have stream manipulators here, so we don't want people to
think, that we are talking about streams and
2. strings already can be concatenated with operator +. Therefore this
is an intuitive and not very surprising interface for string
concatenation.
People might just think, they can add numbers to strings as well without
a "cat"-object. There is some room for confusion, but it is much less,
than people thinking, strings are a kind of streams. Maybe "cat" is not
the best name for this function template, it should express, that here
the concatenation includes conversions.
We also need an extensible way to define these conversions, because we
also will want to add e.g. complex