Note: This is not a question whether I should \"use list or deque\". It\'s a question about the validity of iterators in the face of insert()
.
list
is a very inefficient way to store a string. It is probably 10-20 times larger than the string itself, plus you are chasing a pointer for every character...
Have you considered using std::dequeue
instead?
[edit]
To answer your actual question, adding and removing elements does not invalidate iterators in a list
... But end()
is still going to be end()
. So you would need to check for that as a special case at the point where you insert the new element in order to update your readpos
iterator.