What's going on here? Even the tutorials I've read use code with the three-parameter version, so why is it that the two-parameter version is the actual standard? What's equivalent standard code for using the three parameter version?
Your streambuf header has a non-standard extension, that's pretty common.
If you want to set pptr() different from pbase() in portable manner, you can pbump() it after calling setp() (note that it's rarely needed - unlike in the get area where you can putback to access something to the left of the next pointer)
PS: found an example on SO demonstrating a socket-backed stream.. indeed, here pptr() needs to be set different from pbase()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
int fdbuf::sync() {
if (this->pbase() != this->pptr()) {
std::streamsize size(this->pptr() - this->pbase());
std::streamsize done(::write(this->fd_, this->outbuf_, size));
// The code below assumes that it is success if the stream made
// some progress. Depending on the needs it may be more
// reasonable to consider it a success only if it managed to
// write the entire buffer and, e.g., loop a couple of times
// to try achieving this success.
if (0 < done) {
std::copy(this->pbase() + done, this->pptr(), this->pbase());
this->setp(this->pbase(), this->epptr());
this->pbump(size - done);
}
}
returnthis->pptr() != this->epptr()? 0: -1;
}
While I agree that the second version is more convenient (like the three-parameter setg), I think someone decided to take some liberties with the standard library.
I think what one would have to do is repeatedly call pbump to advance the put pointer. Not exactly convenient or efficient, but I'm not sure what else could be done.