
On 01/29/2011 02:41 AM, Ivan Le Lann wrote:
----- "Patrick Horgan"<phorgan1@gmail.com> a écrit :
On 01/28/2011 09:59 AM, Dean Michael Berris wrote:
On Fri, Jan 28, 2011 at 7:20 PM, Dean Michael Berris <mikhailberis@gmail.com> wrote:
So the interface I was thinking about (and suggesting) is a lot more minimal than what rope or std::string have exposed. I think when I do finish that design document (with rationale) it would be clear why I would like to keep it immutable and why I would prefer it still be called a string.
Let me finish that document -- expect something over the weekend. :) And I stopped before I write too much -- the initial version is already up: https://github.com/downloads/mikhailberis/cpp-string-theory/cpp-string-theor... -- I'll give it more information and the actual interfaces and implementation as soon as I get some Z's. :)
You mention that your string is thread safe by design, but you only solve the problem of mutating the data of a string, your references to the pieces from which you compose a string are not thread safe, since they are mutable, right? I don't think so. Isn't the easiest way towards proper composition to consider that the whole is the same as the part? I see the "chain" (I voted for that one!) as an immutable tree of immutable leafs. I think this can be naïvely seen as the following recursive boost::variant: But if everything is immutable, what if you add a phrase in the middle of a line.
chain thesentence=chain("I like bananas. Yes I do.") becomes: thesentence=thesentence.insert(atpos15, " all the time"); To create a sentence, "I like bananas all the time. Yes I do." Originally the tree would have one element demarcating the beginning and end of the original string. After the addition, you could have a tree with three elements two pointing into the original string, "I like bananas" and ". Yes I do." and a middle one pointing at the beginning and end of " all the time". To insert that something had to change. A list or chain of 1 element became a list or chain of 3 elements. Whatever changed has to be thread safe. Of course you say leafs are immutable, so the original leaf that pointed at the beginning and end of the original string would still exist, but now be unused, right? Am I understanding this correctly? Patrick