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().
insert()
if (readpos == buf.begin()) { buf.insert(buf.end(), newdata.begin(), newdata.end()); readpos = buf.begin(); } else { --readpos; buf.insert(buf.end(), newdata.begin(), newdata.end()); ++readpos; }
Not elegant, but it should work.