
On Thu, Jan 27, 2011 at 10:05 PM, Chad Nelson <chad.thecomfychair@gmail.com> wrote:
On Thu, 27 Jan 2011 19:22:17 +0800 Dean Michael Berris <mikhailberis@gmail.com> wrote:
<emphasis> If you were to ask *me* and *me alone*, of course *I* think that *my* vision for boost::string *should* be the way strings are dealt with. Of course that's ego-maniacal and self-centered of me to say so, but if I had to be explicit about it and take a position I would say exactly that: std::string is broken and it doesn't deserve to be the string implementation that C++ programmers have to use. </emphasis>
Question: if you replaced std::string with your immutable string, how would you build strings one character at a time for it?
Good question. See answer below.
std::back_inserter wouldn't be possible. A large number of current uses for std::string require that, all the way up to std::copy. Building them in an array or vector<char> would be less efficient due to an extra copy.
Actually, what std::copy requires is an iterator to model the OutputIterator concept. This means, std::back_inserter would somehow be analogous to std::ostream_iterator<>, and while we're at it, you build strings with a "stream" instead of modifying an already created string. :)
I'm not objecting to the basic idea -- you made an excellent case for it in the message this is a reply to, and it convinced me. I just can't see any way that it could replace mutable strings, as you're asserting.
The first step is to think about a string as something that, once constructed and is considered "live", would not need to be modified. Then the question becomes "so how do we build strings from other strings" and there are two possible answers: 1) build it using the ostringstream model 2) concatenate strings to build new strings. Either approach yields different performance characteristics and you end up with having clearly defined semantics for constructing strings.
So why would I not want to call it boost::string? ;)
Because it isn't a string, in the accepted C++ sense? :-)
Well one thing is certain: I suck at names. So if there's a suitable name that better models my notion of a string, then I'm open to suggestions. Although I maintain, what *I* think an immutable string representation is what will make std::string's brokenness way more obvious. As much as I would like to call it just `boost::string` I may be in the minority on this point so I'm willing to be convinced of using a different name. :) -- Dean Michael Berris about.me/deanberris