I am writing a custom binary stream buffer inheriting from the standard std::streambuf interface. This stream buffer needs to support writing and reading to an external block of memory (not owned by the stream). So far, I could get away with only overriding the underflow and overflow member functions, which call setp, pbump, and setg with the right positions, handle the logic to circumvent the limitation of Microsoft's STL only accepting int values for offsets (which causes problems with large objects), and get/set a byte using pptr and gptr.
This has worked well for a while. Recently, when attempting to use this class in another context, the input stream using my stream buffer went into fail state almost immediately. I realized that the default implementation of std::streambuf::seekoff is to do nothing and return -1, which is why the fail bit was set. I guess previous usage of the stream buffer never ended up calling seekoff, and this went unnoticed.
Doing some research on other people's experience in implementing custom stream buffers, I rarely see seekoff (and it's companion seekpos) being overriden. Boost ASIO's basic_streambuf does not. This article on writing custom stream buffers and this other article (both show up on the first page in a Google search) do not.
I did see the various STL implementations of basic_stringbuf use it, though (MSVC, libstdc++, libc++).
Is it an error not to implement seekoff and seekpos? Based on what I understand of streams, the implementation in basic_stringbuf effectively forwards the call to setg and setp with the proper read/write pointers, and this implementation should be applicable to all streams. If so, why is this not the default behavior? I understand it may not be optimal, but the standard does provide working and non-optimal default implementations for xsgetn and xsputn. What I am missing?